Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Help, applescript to open/close an app

I've run into a problem on creating an applescript that will open or close a specific app if it is already running, unless it was just opened. I have tried to write it two ways.


tell aplication "calculator" to activate

end tell

tell aplication "calculator" to close if aplication "calculator" is running

end tell


Obviously this gets me noo where because it just opens and then closes the calculator. So I thought maybe i'd try reversing it.


tell aplication "calculator" to close

end tell

tell aplication "calculator" to activate if aplication "calculator" is closed

end tell


Works for opening the calculator the first time, but then always open calculator back up once closed. I need help to write an applescript along the lines of:


tell aplication "calculator" to activate

end tell

tell aplication "calculator" to close if aplication "calculator" is running unless "calculator" was activated by above tell statement

end tell


Or maybe an if else statement. But i think I'm going to have to have something that can check if the app is running before it closes it.


I like assigning triggers to my F keys and just want a script I can assign to one key that will open/close my calculator. I'm open to ideas. I'm willing to bet there is an easier way to do this, but I'm new to using applescripts and could use some help.

AppleScript-OTHER, OS X Mavericks (10.9.1)

Posted on Jan 9, 2014 1:46 AM

Reply
Question marked as Best reply

Posted on Jan 9, 2014 7:03 AM

Try something like


tell application "System Events"

get name of every process whose name is "Calculator"


if result is not {} then


tell application "Calculator"

quit

end tell

else

tell application "Calculator"

activate

end tell

end if


end tell



BTW when posting a question here it is best to mark it as such. You'll get more responses if people know you are asking a question rather then just making a statement.

2 replies
Question marked as Best reply

Jan 9, 2014 7:03 AM in response to Dahmenator

Try something like


tell application "System Events"

get name of every process whose name is "Calculator"


if result is not {} then


tell application "Calculator"

quit

end tell

else

tell application "Calculator"

activate

end tell

end if


end tell



BTW when posting a question here it is best to mark it as such. You'll get more responses if people know you are asking a question rather then just making a statement.

Help, applescript to open/close an app

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.