Quitting applications

Please help!
I have just started to look at Applescript and I am trying to write a really simple script for quitting a specific application and also a script for quitting all open applications. (I plan to execute the scripts from a menu in Filemaker which gives access to our databases and opening and quitting applications) Naturally I only want the application to quit if it is allready open. Either way I write the script however, the application opens first and then quits. I am sure there must be a simple way to determine the application status and stop the application from opening if it is allready closed. Can anyone help???
Vegard

: Please help!
: I have just started to look at Applescript and I am
: trying to write a really simple script for quitting a
: specific application and also a script for quitting
: all open applications. (I plan to execute the scripts
: from a menu in Filemaker which gives access to our
: databases and opening and quitting applications)
: Naturally I only want the application to quit if it is
: allready open. Either way I write the script however,
: the application opens first and then quits. I am sure
: there must be a simple way to determine the
: application status and stop the application from
: opening if it is allready closed. Can anyone help???
: Vegard
The following AS should “quit” all open applications. (not in background).
– lets get a list of all applications (excluding background apps) and copy the result to “openApps” tell application “Finder”
get the application processes whose visible is true
copy the result to openApps
– get the number of applications listed in “openApps”
count the items of openApps
copy the result to openAppsNum
copy 1 to i
– this loop goes through the list of open apps and tells them to quit (“quit” is part of the “Required Suite”)
repeat while i ² openAppsNum
tell application (item i of openApps as string)
quit
copy i + 1 to i
end tell
end repeat end tell
Hope this helps !

: Please help!
: I have just started to look at Applescript and I am
: trying to write a really simple script for quitting a
: specific application and also a script for quitting
: all open applications. (I plan to execute the scripts
: from a menu in Filemaker which gives access to our
: databases and opening and quitting applications)
: Naturally I only want the application to quit if it is
: allready open. Either way I write the script however,
: the application opens first and then quits. I am sure
: there must be a simple way to determine the
: application status and stop the application from
: opening if it is allready closed. Can anyone help???
: Vegard
Hi, Vegard.
The Finder maintains a list of the running processes, so you can consult this to see if your application is open:
---- set appName to “SimpleText” – for demonstration purposes
tell application “Finder” set appIsOpen to (process appName exists) end tell if appIsOpen then tell application appName to quit ----
You have to be careful when “quitting all open applications”, as there are some that work in the background (such as extensions) which you may not wish to quit. The following works for me:
---- try tell the application “Finder” to ¬ get (the name of every process whose file type is “APPL”) as list
repeat with thisName in the result tell the application thisName to quit end repeat
on error end try ----
The ‘try’ block traps an error that occurs if there are no “APPL” processes and the ‘as list’ coercion ensures that that line returns a list, even when there’s only one name.
NG

1 Like

Thanks a lot for useful help!
I am very grateful…
Would it be possible to make an exception to the quit all command, for instance if I want to quit all applications except filemaker?
Vegard