PDA

View Full Version : Applescript activation switch?




wrignj08
Jun 14, 2011, 01:04 AM
Hey all, i need an applescript that will activate an app if it is not currently open or if it is open quit it (so basically the script will act like an activation switch). any suggestions thanks.



kainjow
Jun 14, 2011, 01:14 AM
set myAppName to "Stickies"
set isRunning to false
tell application "System Events"
if exists process myAppName then
set isRunning to true
end if
end tell
if isRunning is true then
tell application myAppName to quit
else
tell application myAppName to activate
end if

wrignj08
Jun 14, 2011, 01:34 AM
That works perfectly thanks

wrignj08
Jun 21, 2011, 10:03 AM
Ok so maybe it is not perfect, for example it does not appear to work for textedit. it will open the app but then the script will not quit it. suggestions?

set myAppName to "textedit"
set isRunning to false
tell application "System Events"
if exists process myAppName then
set isRunning to true
end if
end tell
if isRunning is true then
tell application myAppName to quit
else
tell application myAppName to activate
end if

kainjow
Jun 21, 2011, 10:06 AM
It's case sensitive. Use "TextEdit" instead of "textedit".

wrignj08
Jun 21, 2011, 10:19 AM
Thanks that works :-)