How to get a script file to accept user name thru dialog box, save name, but have a different script operate from that point on - scripting

I am attempting to accept a user name through an Applescript script: I have accomplished this. So I am thinking that I need to have the name saved to a file because thats all i need and have another piece of script activate every time I click on the app from that point and retrieve the name. My question is how would I get it to not accept the original script after the first run.

AppleScript Overview
| Scripting with AppleScript
One way would be to use properties.
property MyUserName : ""
if MyUserName is "" then
display dialog "User Name:" default answer "" buttons {"Cancel", "Continue…"} default button 2 with icon 0
copy the result as list to {button_pressed, text_returned}
if button_pressed is "Cancel" then
beep
return
end if
if text_returned is not "" then set MyUserName to text_returned
else
display dialog "Stored user name: " & MyUserName buttons {"Ok"} default button 1 with icon 1
end if
The property-value is stored within the compiled script. It also works when the script is saved as an application. Opening and recompiling it in AppleScript Editor resets the values.

Related

Disable File>Share in Excel with VBA

I need a way to disable the ability for a user to go to (or use) the menu File > Share
I have similar for other save commands like below but need something for this feature as well
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save").Enabled = False
I have tried:
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Share").Enabled = False
to no avail
My aim is to stop users saving copies of this file (Hosted on a server), I fully understand Excel isn't meant to be secure and there is always a way to do this but want to make it as hard as I can for the average Joe
Regards
You could use a for each loop to extract the available commands:
' Iterate available commands from the file command bar.
Sub PrintAllCommandBarControlNames()
Dim cbControl As CommandBarControl
For Each cbControl In Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls
Debug.Print cbControl.Caption
Next
End Sub
Run on Excel 2010, I couldn't find a share option. Might just be my system. The above returned:
&New...
&Open...
&Close
&Save
Save &As...
Single Web Page (*.mht)
Save &Workspace...
File Searc&h...
Per&mission...
Per&mission
Ch&eck Out
Ch&eck In...
Ve&rsion History...
We&b Page Preview
Page Set&up...
Prin&t Area
Print Pre&view
&Print...
Sen&d To
Propert&ies
&Recent File Name Goes Here
&Recent File Name Goes Here
Sign ou&t
E&xit Excel
The 'backstage' menu (that you get when you click top left File menu) is effectively part of the Ribbon, and not a Command Bar. If you tried disabling Save for instance, using your example, you'll find they don't work on 2010/2013 etc.
There is this answer which tells you how to manipulate those menu items in the ribbon: Remove "Save & Send" from File menu in Excel 2010 using custom XML and one of the items is called TabShare.

Code "delete my account" button

Im using vb 2013. I tried to code my delete button after adding SQL delete in my Database. I wrote code in the class (I called it userFunc) calling the SQL DeleteItYourself with the variable DeleteIt. I created button with the toolbox and double clicked it, now I'm lost. I have session in the Login button to make sure it presents the user nickname. I redirected it to the homepage when the "I want to delete my account" located. Iactually don't know what to do with the button. I want it to call the function DeleteIt, but before the function Delete I want it to ask the user with some pop up alert if he's sure. Any ideas how to code my button?
(I'm a high school student and it's my project, they don't ACTUALLY teach us Java, unfortunately... They tell us to copy paste and try to understand)
Use this as a starting point:
If MsgBox("Are you sure you want to delete your account? This cannot be undone.", _
(MsgBoxStyle.Critical + MsgBoxStyle.OkCancel), _
"Confirm Account Deletion") = MsgBoxResult.Ok Then
UserFunc(DeleteIt)
End If
MsgBox displays a message box to the user, waits for a response, and returns the value of the button pressed. In the code above, the three arguments are:
The message to display
The style of the message box. Note how these are numeric values and can be added.
The title of the window.

How to save changes of a saved text file in VB.NET

I have a text editor that can open text files .txtand puts the text in a textbox. The user can also save the text to a .txt file.
How can the user save the changes of that text file that was saved recently?
Also, If the user opened a txt file how can the text editor change the text file to what the user changed?
Hope you understood that. Thanks in advance.
Since I don't know what you've done so far I will take this from the beginning...
For this you will need these components:
A SaveFileDialog
An OpenFileDialog
Three buttons (or menuitems), labeled: "Save", "Save As", "Open"
And I actually recommed using a RichTextBox instead of a regular TextBox.
.
To start, we put a variable in the code to know what file was saved before:
Dim LatestFile As String
Then, go to the properties of your Save- and OpenFileDialog and put this in the Filter field:
Text files (*.txt)|*.txt
Then you double-click the SaveFileDialog which should write the SaveFileDialog_FileOk event in your code. There you put:
LatestFile = SaveFileDialog1.FileName
RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
And then double-click the OpenFileDialog, and enter this code:
LatestFile = OpenFileDialog1.FileName
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
And then for the buttons:
The "Open" button:
OpenFileDialog1.ShowDialog()
The "Save" button:
If Not LatestFile = "" Then
RichTextBox1.SaveFile(LatestFile, RichTextBoxStreamType.PlainText)
Else
SaveFileDialog1.ShowDialog()
End If
And the "Save As" button:
SaveFileDialog1.ShowDialog()
.
Hope this helps!
If I understood your question: you want your text editor application to detect changes that happened to the source text file that it is currently viewing to the user and if it detects a change, it should update its text box to display the latest file for the user.. am I right?
If that is the case, one way to do that is to use a Timer. Every time the timer tick event is triggered, you should check the date of the last modification to the file. If it is greater than the date that you have checked while opening the file for the first time, then the file had gone through some changes. Reload the file contents into the text box.
Another way (without using Timers) is to only check for the modification date once the application window is activated. Since the user will have to change the focus of the program to, say Notepad to do changes to the text file, then once the user returns focus to the Text Editor Application, use the Window Activate or Click event to check the file modification date.

Applescript to input text in website

set query to text returned of (display dialog "Enter Query" default answer "" buttons {"Input", "Cancel"} default button 1)
open location "http://www.soundcloud.com/"
delay 1
tell application "System Events"
key code 48
end tell
delay 1
query
So i'm trying to make an applescript that:
1) Prompts with dialogue box to enter data
2) Opens up webpage
3) Presses tab to get to first text box
4) Pastes data from step 1
I've figured out how to get to up to step 4 but when i print the query variable it only prints it within the applescript not the webpage.
set query to text returned of (display dialog "Enter Query" default answer "" buttons {"Input", "Cancel"} default button 1)
open location "http://www.soundcloud.com/"
delay 1
tell application "System Events"
key code 48
delay 1
keystroke query
end tell
I needed to add keystroke into the commandline
Try this instead:
set query to text returned of (display dialog "Enter Query" default answer "" buttons {"Input", "Cancel"} default button 1)
tell application "Safari"
if not (exists document 1) then reopen
activate
set URL of document 1 to "http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi"
delay 3
do JavaScript "document.getElementsByName('SCREEN')[0].value=" & quoted form of query & "" in document 1
end tell

Use Applescript to pass Path and File Name to Save as Print Dialog box for PDF's

I have a script that opens an email and then I want to save it as a PDF. The script works but I cannot figure out how to pass the path and folder name to the dialog box that results after I call Save as a PDF. This is my script so far.
global FlName
tell application "Mail"
set theMsg to selection
open selection
set Dialogresult to the button returned of (display dialog "Process this email and Print as PDF" buttons {"Yes", "No"} default button "Yes")
if Dialogresult is "Yes" then
repeat with selectMsg in theMsg
tell selectMsg
--set background color to red --Show message processed
set FlName to subject
set check to count every word of FlName
--display dialog check
set FlName to (my FixFileName(FlName)) --strip bad characters
end tell
end repeat
set process_name to "Mail"
activate application process_name
tell application "System Events"
tell process process_name
--display dialog "proposed File Name" & return & FlName
keystroke "p" using command down
delay 2
set PDFref to sheet 1 of window 1
click menu button "PDF" of PDFref
click menu item "Save as PDF…" of menu 1 of menu button "PDF" of PDFref
tell application "Mail"
display dialog "Proposed Name " & my FlName default answer FlName & "change in the Box if Not OK"
set FlName to text returned of result
end tell
keystroke FlName
end tell
end tell
else
set Dialogresult to the button returned of (display dialog "Close this eMail" buttons {"Yes", "no"} default button "No")
if Dialogresult is "Yes" then
close window 1
end if
end if
end tell
on FixFileName(str) --Deletes characters that cannot be used in file names
set fixed_string to {}
set bad_char to {":", "/"}
repeat with c from 1 to (count every character in str)
if bad_char contains (character c of str) then
set end of fixed_string to "-"
else
set end of fixed_string to (character c of str)
end if
end repeat
fixed_string as string
end FixFileName
Peter
One other possiblity to consider is writing a separate PDF Applescript and adding it to the PDF pulldown menu via "Edit Menu". (Not sure what application you would have to TELL... Check out this link for a lead: http://hints.macworld.com/article.php?story=2004122222145585) Here's the excerpt from Mac Help:
You can add your own items, such as applications and AppleScript
scripts, to the PDF pop-up menu. For example, you can add an
AppleScript script that applies a Quartz filter to a PDF file, or you
can add an application that opens the PDF file immediately after it’s
created.
If you create a Print workflow plug-in in Automator, that plug-in is
added automatically. For more information, open Automator, choose Help
Automator Help, and search for “Print workflow plug-in.”
To add an item to the PDF pop-up menu:
Choose File > Print.
Choose Edit Menu from the PDF pop-up menu.
Click the Add (+) button and select the item you want to add.
For example, if you want to open a newly created PDF file in Adobe
Acrobat, select Adobe Acrobat. If you’ve created an AppleScript script
that applies a Quartz filter to a document, choose that script.
An alias to the item is saved in the PDF Services folder in your
Library folder.
If you're unable to set the name of the PDF when it's generated, but know where it was saved and what it was saved as, use AppleScript to rename and move the file to where you want instead. It might be kind of kludgy to select the location and the name, using a display dialog to let the user choose the name and a choose folder to allow them to select the location.
Following #Chuck's answer, yes that is kind of kludgy, but there is the choose file name command, which lets the user choose the name as well as the location...
set the FlName to (choose file name with prompt "Choose a name and location for the new PDF document:" default name "untitled.pdf")
However, this does not actually create the file. The commands below do.
open for access FlName
close access FlName