When I save the following script as compiled and open it, I have to try to open it two times to actually open it.
That means I have to do two of the following actions (or do one of these two times):
¢ Open from the Finder
¢ Open from the Terminal (open command)
¢ Open… from Script Editor’s File menu
¢ Open Recent from Script Editor’s File menu
to get it to open.
After the first open, Script Editor mostly behaves as if nothing had happened. The exceptions:
¢ If I try to open it again, Script Editor will open it.
¢ If Script Editor is not already open, it will launch, but not create the blank window Untitled.
After I do open it:
¢ The title bar says Window with no proxy icon, and is not command-clickable.
¢ The Run button will compile the script (but not run it) if there are any uncompiled changes.
¢ I can edit and save and all that stuff, and the close button will update its appearance according to whether there are saved changes.
What does not work:
¢ Trashing the preferences file
¢ Saving using Terminal command “osacompile”
¢ Saving it again
I repeat, this problem exists only with the following script. If I had not written this script, nothing would go wrong.
Saving the script as text almost eliminates the problem. The Run button problem is not fixed.
I suspect something in the script that make Script Editor do some action on compiling it.
set wasopen to true
try
tell application "System Events" to process "QuickTime Player"
on error
set wasopen to false
ignoring application responses
tell application "QuickTime Player" to activate
tell application "QuickTime Player" to close window 1
tell application "System Events" to set visible of (process "QuickTime Player") to false
end ignoring
end try
tell application "QuickTime Player"
open ("Macintosh HD:System:Library:LoginPlugins:BezelServices.loginPlugin:Contents:Resources:volume.aiff")
set visible of window 1 to false
if not wasopen then tell application "System Events" to set visible of (process "QuickTime Player") to false
play document -1
delay 0.5
close document -1
end tell
if wasopen = false then tell application "QuickTime Player" to quit
the easiest way to play a sound file in the background is using Play Sound
set sysLibrary to (path to library folder from system domain as text)
set volumeAIFF to sysLibrary & "LoginPlugins:BezelServices.loginPlugin:Contents:Resources:volume.aiff" as alias
tell application "Play Sound" to play volumeAIFF
maybe this version of your original script works more reliable
set sysLibrary to (path to library folder from system domain as text)
set volumeAIFF to sysLibrary & "LoginPlugins:BezelServices.loginPlugin:Contents:Resources:volume.aiff" as alias
tell application "System Events" to set isRunning to (exists process "QuickTime Player")
if not isRunning then launch application "QuickTime Player"
tell application "System Events" to set visible of (process "QuickTime Player") to false
tell application "QuickTime Player"
open volumeAIFF
play document 1
close document 1
end tell
if not isRunning then quit application "QuickTime Player"
Thanks, I already know about Play Sound. I was trying to do stuff without it.
This is better. It doesn’t solve my problem (I still need to open it 2 times), but I did not know about exists process and launch.
The delay is necessary, since the audio file takes a while to play, and I need to hide the individual window if Quicktime was open before because the user may have had other QuickTime documents open.
By the way, when you save it, does it open the first time?
Interesting one! With Script Editor 2.0, on both my Tiger and Jaguar machines, it takes two goes to open the script in Script Editor using the Finder and the name of the window that eventually opens is “Window”, not the name of the file.
The problem only seems to occur when the last line in a script is a one-line ‘if’ statement and ((its condition is an expression) and/or (the rest of the line contains another ‘if’) and/or (the rest of the line contains an application specifier)).
Weird. Definitely a bug and not your fault. The work-round is to make something else the last line of the script. Either:
Put a comment line or at least two empty lines after the last line, or:
Make the ‘if’ and/or ‘tell’ statements multi-lined, or:
Put the entire script in a handler ” perhaps an explicit run handler.
Edit: Updated and corrected in the light of further tests.
If you like. The problem appears to be the Script Editor 2.0 application rather than the system itself. I get the same effect on both my Tiger and Jaguar machines. The Script Editor 1.9 that originally came with the Jaguar system opens the file first time.
When using any method to open it (Finder, Terminal, Script Editor (Open… or Open Recent), drag and drop, Apple recent documents), you need to do a total of 2 actions to open it.
The Run button needs to be clicked once to compile uncompiled changes, and a second time to run the script. The same is true for uncompiled (text) scripts.