Re: Quit All Applications
Re: Quit All Applications
- Subject: Re: Quit All Applications
- From: "Marc K. Myers" <email@hidden>
- Date: Wed, 24 Jan 2001 11:52:31 -0500
- Organization: [very little]
Nigel Garvey wrote:
>
Subject: Re: Quit All Applications
>
Date: Wed, 24 Jan 2001 11:30:41 +0000
>
From: Nigel Garvey <email@hidden>
>
To: "AppleScript Users" <email@hidden>
>
>
"Marc K. Myers" wrote on Wed, 24 Jan 2001 00:30:40 -0500:
>
>
[Script snipped]
>
>
>
>This script, as written, will send a "quit" to the Finder for each app
>
>that's running, quitting the Finder and not the apps. You can't put a
>
>"quit" inside a tell to the Finder. You have to put it in a separate
>
>handler:
>
>
>
>tell application "Finder"
>
> .................
>
> tell me to doQuit(a)
>
> .................
>
>end tell
>
>
>
>on doQuit(theApp)
>
> tell application theApp to quit
>
>end doQuit
>
>
... or, of course, only use the Finder to identify the apps. This version
>
also preserves background processes:
>
>
try
>
tell the application "Finder"
>
get (the name of every process whose file type is "APPL") as list
>
end tell
>
>
repeat with thisName in the result
>
tell application thisName to quit
>
end repeat
>
on error
>
end try
>
>
The 'try' block is in case there are no applications open (trying to get
>
their names produces an error) and the 'as list' is in case there's only
>
one (the result is a simple string). You don't have to worry about
>
excluding the Finder itself as it doesn't appear in the processes.
Any script that's going to quit all application processes needs to
exclude the process running the script, otherwise it would kill itself
before it completed its cycle. In the Finder tell, you'd say:
set myName to name of (path to me)
Then, in the repeat that does the quitting you'd say:
if thisName is not myName then
tell application thisName to quit
end if
If the script is an applet, it'll quit at completion. If it's being run
from an application, that program will stay active.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[1/24/01 11:51:41 AM]