Script to close all open programs

I searched but couldn't find an answer, so please forgive me if I've overlooked something. I'm attempting to put together a simple script to close all open applications (prior to shutting down, for example). I hobbled together the following code from examples I've found online and from answers to other's questions. My issue, however, it that in its current iteration it doesn't close all applications. Could anyone please tell me what I'm doing wrong?


tell application "Firefox" to activate
tell application "System Events"
tell process "Firefox"
keystroke "q" using command down
delay 1
keystroke return
end tell
end tell

tell application "System Events"
set theProcesses to every process whose visible is true and name is not "Finder" and name is not (name of me)
end tell

repeat with i from 1 to (count of theProcesses)
set thisProcess to item i of theProcesses
try
tell application (name of thisProcess) to quit without saving
end try
end repeat

Powermac Dual 1.8 ghz G5, Mac OS X (10.4.11)

Posted on Aug 6, 2008 6:56 PM

Reply
6 replies

Aug 6, 2008 8:13 PM in response to Spakman

Your problem might also be the use of:

tell application (name of thisProcess) to quit without saving


I'd expect this to choke on any application that doesn't understand the 'without saving' construct. Not all applications do - especially those that are not document-based (Firefox being one example - you don't save the current document in Firefox when you quit).

The telling detail would be the applications that are still running after your script runs. What are they?

Aug 7, 2008 4:35 AM in response to Spakman

Save the following code as an application (AppleScript applet):

tell application "System Events" to set pNames to name of every process -- Obtain names of all processes.

repeat with i from 1 to (count pNames) -- Provide quote marks around each process' name.
set (item i of pNames) to quoted form of (item i of pNames)
end repeat

set {oAStid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "} -- Corerce 'list' contents to a 'string'.
set pNames to pNames as string
set AppleScript's text item delimiters to oAStid

try -- Ignore any AppleScript error message(s).
do shell script ("killall " & pNames) -- 'killall' the processes.
end try

Aug 18, 2008 7:28 AM in response to Spakman

I use something like this at the end of the day:

tell application "Extensis Suitcase X1"
quit
end tell
tell application "Mail"
quit
end tell
tell application "Adobe Photoshop CS"
quit
end tell
tell application "QuarkXPress Passport"
quit
end tell
tell application "Adobe GoLive CS"
quit
end tell
tell application "iChat"
quit
end tell
tell application "Acrobat 6.0.2 Professional"
quit
end tell
tell application "Microsoft Excel"
Quit
end tell
tell application "Firefox"
quit
end tell
tell application "TextEdit"
quit
end tell
tell application "System Events"
shut down
end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Script to close all open programs

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