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)