quiting all applications

Hi all scripters…

am very new to scripting…
just trying it recently …
done one to start playing diablo it works. but before playing the game … i wish to quit all running application (in order to make the game run smooth).

i got this one frm the web after some extensive searching. but it doesn’t seem to be workin anymore.


property excludedApps : {"Firefox"}

--The Finder and background processes are
--not affected because their file

type is not APPL

tell application "Finder"
	set theProcs to every process whose (file type is "APPL" and name is not in excludedApps)
end tell

repeat with x in theProcs
	set appName to name of x
	tell application appName to quit
end repeat

the returned error is … “The variable type is not defined”
what can i do?

thanks in advance.

T@

You just cut&pasted without looking at the script. The line beginning with “type” should be part of the comment on the previous line…

property excludedApps : {"Firefox"}

--The Finder and background processes are
--not affected because their file type is not APPL

tell application "Finder"
   set theProcs to every process whose (file type is "APPL" and name is not in excludedApps)
end tell

repeat with x in theProcs
   set appName to name of x
   tell application appName to quit
end repeat 

j

alright thanks jobu.
but even after that i still get an “NSCannotCreateScriptCommandError” error

on the line

every process whose (file type is "Apps" and name is not in excludedApps)

sorry about all these but am really new …
am just trying to learn by cutting and pasting …
if it works … i’ll then examin the script. :oops:

Well, I couldn’t get that part to work either, no matter what I did. So I put that test further down, in the repeat.
You MUST run the part that just gets your running processes, so you can see the list. It’s a lot more than you think, I bet. I have a few running that you might think of as “background,” but they are applications. Then you can just copy/paste them into the exclusions, other than ones you want to quit.

property excludedApps : {“loginwindow”, “Dock”, “SystemUIServer”, “MaxMenus”, “TigerLaunch”, “Transport Monitor”, “iCalAlarmScheduler”, “LCCDaemon”, “Default Folder X”, “Spell Catcher UI Server”, “Spell Catcher”, “Spell Catcher SpellServer”, “Safari”, “BBEdit”, “Eudora”, “Image Capture Extension”, “Script Editor”, “System Events”}
The Finder is not affected because its file type is not APPL

tell application “Finder”
set theProcs to name of (every process whose (file type is “APPL”))
end tell

repeat with x in theProcs
if x is not in excludedApps then
tell application x to quit
end if
end repeat

sigh

thanks … but … no luck … :frowning:
nvvm … will do trial and error …

anyway … thanks again
T@

Try this one instead…

property excludedApps : {"Firefox", "Script Editor", "System Events"}

tell application "System Events" to set allProcesses to displayed name of (every process whose file type is "APPL")
--> Result: {"loginwindow", "Dock", "SystemUIServer", "USBserver", "NETserver", "ControlCenter", "LOGINserver", "Fax Server", "Palm Desktop Background", "Transport Monitor", "SpeechSynthesisServer", "LunchMenu", "Firefox", "Fax Assistant", "Script Editor", "System Events"}

repeat with tmpProcess in allProcesses
	if (canQuitApp(tmpProcess)) then tell application tmpProcess to quit
end repeat

to canQuitApp(tmpProcess)
	repeat with tmpApp in excludedApps
		if (tmpApp as string) is (tmpProcess as string) then return false
	end repeat
	return true
end canQuitApp

Note that the variable ‘allProcesses’ I listed the value for above has a lot of “stuff” in it. Many of these things are important to other processes and applications I use, so blindly quitting them may not be a good idea. Contrary to what comments in the code you first posted state, many “background processes” can in fact be quit because they are just applications like any other. True, some system processes cannot be quit… but others can be quit and may cause problems, or at least cause you to have to wait for them to launch again if they are quit but needed later. Most necessary functions will relaunch automatically when needed, but just quitting them because they are open may not always be the best option. Also, consider that some apps take up very little memory and only use processing time when ‘in use’, so quitting them may not provide any benefit.

j

thanks again jobu …

will try it when i get to my mac.
Thanks again.

T@

Background applications never are visible.
So you should search for processes that are visible and you will not have to care for the background apps.

property excludedApps : {"Firefox", "Finder", "Script Editor"}
tell application "System Events"
set theProcs to name of every process whose visible is trueend tellrepeat with x in theProcs if x is not in excludedApps then try tell application x to quit end try end ifend repeat

aah! Nice Fischer! That works well … but only with applications that are, right, visible and not “hidden” as in “cmd + H” …
now … on to control it to quit aplications that are hidden but aren’t background apps. :wink:
Thanks a million again Fischer!

T@

with help from a fellow macuser .
managed to come up with one that’s able to quit all running application but excludes the ones u specify.

heres it.

property excludedApps : {"Finder"}

set AppsList to (read alias "Worker:Users:GHT:Desktop:InComing:AppsList.txt")

tell application "System Events"
	set theProcsV to name of every process whose visible is true
	set theProcsH to name of every process whose visible is false
end tell

repeat with v in theProcsV
	if (v is not in excludedApps) then
		try
			tell application v to quit
		end try
	end if
end repeat

repeat with h in theProcsH
	if (h is not in excludedApps) then
		if (h is in AppsList) then
			try
				tell application h to quit
			end try
		end if
	end if
end repeat

where AppList.txt is a list of applications frm the application folder and utility folder listed on a txt file stored some where. you may want to have a script that every 3 monthly (or whatever duration you prefer) generate a list of all the application names aivailable.

Cheers
T@

property excludedApps : {“Firefox”, “Finder”, “Script Editor”}

tell application “System Events”
– the following is the old code:
– set theProcs to name of every process whose visible is true

-- the following is the new code:
set theProcs to name of every process whose background only is false

end tell

repeat with x in theProcs
if x is not in excludedApps then
try
tell application x to quit
end try
end if
end repeat