seems silly, but i have a fundamental problem.
i wrote a program that can only run as a script in Script Editor.
How do i quit it?
I know i can use return in the main code.
however i would like to quit the script from a sub-routine.
i only want to quit the script, not the Script Editor application itself.
how?
This is a contradiction in terms, you can not quit the script keeping it open.
The point is, if Script Editor is open, the “me” statement refers to the application Script Editor.
If you save your script as an application or run it from a menu, the “me” statement
refer to the script itself
I think you just want to stop the script while it’s running in the Script Editor. If so, then:
tell application "System Events" to tell process "Script Editor.app" to keystroke "." using command down
delay 0.5
display dialog "I never get here, because I stopped."
Thank you!
I had thought of exactly the same but found it a bit silly.
How odd! and i thought, there must be a neat way to simply interrupt the execution of a script.
so yes, this works:
tell application “iTunes”
display dialog “now quit”
my quitme()
display dialog “didn’t work” – will not show
end tell
on quitme()
tell application “System Events” to set frontmost of process “Script Editor” to true
tell application “System Events” to keystroke “.” using command down
delay 0.5
end quitme
however, at times I get an error message like : “System Events got an error: User canceled out of wait loop for reply or receipt.”
not very nice
and I won’t be able to switch back to iTunes
Is there no neater way to do this? without leaving iTunes?
understood. Seems the only way. Just thought there must be an easier way to which i don’t know the god-damn syntax.
Your approach is hardly feasable in my case because
a) There are many points within my script where I would want to end the script
b) i would want to end the script from within subroutines (that might be called by other subroutines)
i’ll do it like this:
–code
–code
if my quitme() then return
– code
on quitme()
– do things
return true
end quitme
If you saw my code you would understand…
Thank you both - Stefan and Adam for your immediat help!
Oliver
here the best solution i found to the problem (however it still won’t work for me):
tell application “iTunes”
display dialog “quit now”
my quitme()
end tell
on quitme()
try
with timeout of 0.1 seconds
tell application “iTunes” to display dialog “quitting now.” default button 1
end timeout
end try
tell application “System Events” to keystroke return
end quitme
it works as is, however in my script it doesn’t. quitme() returns to its caller → the script continues anyway. Donno why…
Anyhow, maybe the above helps somebody else
regards,
Oliver