I wanted to have a contest at my place of work, in order to promote the many scripts and Quickeys loaded on their machines. In order to do this, I wanted to modify one script a week with an Easter Egg so it works as follows:
As soon as they activate the script a dialog box would appear that says:
“Congratulations, you are using the script of the week!”
That part is easy, but what I don’t know how to do is the following:
The dialog box would also contain the following text: “Do not show again” with an OK button. If they click the OK button, this popup menu wouldn’t appear next time and the script would just run as designed.
I have never done anything like this with Applescript and don’t know if this functionality is possible?
this is not possible with plain AppleScript. You can only define a button containing text like this
property showFlag : true
display dialog "Congratulations, you are using the script of the week!" buttons {"Do not show again", "OK"} default button 2
if button returned of result is "Do not show again" then set showFlag to false
Stefan,
Thank you very much for your very fast response to my post. This is a great start. Do you think a shell script embedded in the AppleScript could provide the result I am looking for?
This is actually the result you want.
A property is data persisitent (until the script will be recompiled)
so if showFlag is set to false, the next time the script will be run the value is still false
Just add a line to check the value
property showFlag : true
if showFlag then
display dialog "Congratulations, you are using the script of the week!" buttons {"Do not show again", "OK"} default button 2
if button returned of result is "Do not show again" then set showFlag to false
end if
PS: I’d like to specify the problem a bit more detailled:
Like many other things in AppleScript, file-level persistence doesn’t work in every case.
File-level persistence works, if
¢ the compiled script is an applet
¢ the compiled script (file) will be saved, and reopened in Script Debugger
¢ the compiled script (file) will be run from Apple’s Script Menu and returns a value
File-level persistence does not work, if
¢ the compiled script (file) will be recompiled
¢ the compiled script (file) will be saved, and reopened in Script Editor
¢ the compiled script (file) will be run from Apple’s Script Menu and returns no value (like the user has cancelled)
Thanks Stefan,
I soon realized some of these limitations after I placed the compiled script within a Quickey. But that’s okay. I could get around this by targeting the applet that resides somewhere on the machine”this is a Quickey thing so I won’t bog anyone down with the details. The only minor issue is the time it takes to launch the script editor”there is a lag. (And I don’t know if I want these app always running on operators’ machines”unless an app can be hidden from the dock?) Some of the scripts or Quickeys I plan to run are practically instantaneous actions, having script editor open would have to exist.
Another option, which I have seen posts about yet never focused on, is the ability to change a script from within a script? Or maybe I could write a script to replace a Quickey file when a dialog button is clicked?
There’s a lot I need to look into and learn. I have been flooded with other issues at work. This is a great script. Stefan, I really appreciate all of your help.