mass quit apps

i’m trying to make a script that mass quits all visible apps but fprocess is a list and the problems is that i do not always have the same number of prgorams open

tell app "System Events"
to set fprocess to name of every process whose visible is true and name is not "Finder"
end tell
try 
tell application fprocess to quit
end try

thanks tom

You’re trying to quit the list itself, rather than the individual items in it. Try…

tell application "System Events"
	set fprocess to name of every process whose visible is true and name is not "Finder"
end tell

repeat with tprocess in fprocess
	try
		tell application tprocess to quit
	end try
end repeat

j

Yes, but there is one problem I found in doing such thing. I wanted to do the same a few months ago, and but I found out that some apps might ask if ‘user’ wants to save the active doc and that would crash the process since it would wait until it gets an answer (eventually even giving a time out and quitting). Of course you could quit ‘saving false’, but at your risk.

On the other hand, if you don’t specify ‘visibility’ the tell block will return lots of other stuff that I don’t know how to handle, so that would be my question to whoever reads this. Actually all I need is to shut down (safely) my computer.
THX

thanks, this is exactly what i wanted

tell application "system events"
(shutdown)
end tell

This thread was extremely close to a solution and then an alternative solution was given (one that fails to apply a solution to which I am looking).

I’m actually looking to quit all applications that are currently running in the Dock.

I came across this script on (http://www.blankreb.com/studiosnips.php?ID=26) :

tell application “System Events”
set visible of every application process to true
set theProcs to every application process whose visible is true
end tell

set theApps to {}
repeat with i from 1 to count of theProcs
if displayed name of item i of theApps is not “Finder” then
copy displayed name of item i of theProcs to end of theApps
end if
end repeat

repeat with i from 1 to count of theApps
set theApp to item i of theApps
tell application theApp to quit
end repeat

As can be seen, the scipt is actually fairly close in writing to early scripts posted on this page. The above script, however, forces all applications to be visible and then closes them.

I have some knowledge of Applescript, but I tend to avoid too much heavy programming. The above script seems pretty sound, but when I run it I get an error “can’t get item 1 of {}” and then the Script Editor points to the single “Finder” string in this line: (repeat with i from 1 to count of theProcs
if displayed name of item i of theApps is not “Finder” then).

Does anyone have an evaluation of the problem?

I realize that not all applications may quit (due to open un-saved projects), but I think it may be possible to close most of those applications with something like…

tell “System Events”
click button “Save” of window i --since most applications only prompt with a “Save or Cancel” window anyway.

I will greatly appreciate any advice anyone has to offer on further the “quit all applications” endeavor.