Scripting Finder's Contextual Menu

Hi!

Can Applescript be used to insert and execute commands from the contextual menu in Leopard 10.5.1?

I want to be able to command-click at anytime (accessing the contextual menu) and choose from a list of open applications, and Quit any application I choose…maybe a Quit All option as well.

I know that you can Quit from the Application Menu and also from the Dock but I am lazy and my mouse gets tired so I would like a quicker way.

Or, is this an action that at best would require coding a Contextual Menu “.plugin”?

I would greatly appreciate anyone pointing me in either or both directions.

Thanks,

pwilson

Hi pwilson and welcome :slight_smile:

You can’t do this directly in AppleScript but there is an Automator submenu in the contextual menu.
Define a workflow with the Run Applescript action and use this script


on run {input, parameters}
	tell application "System Events" to set runningApps to name of processes whose background only is false and name is not "Finder"
	set appsToQuit to choose from list (theApps & "All applications") with multiple selections allowed
	if appsToQuit is not false then
		if "All applications" is in appsToQuit then
			quitApps(runningApps)
		else
			quitApps(appsToQuit)
		end if
	end if
	return input
end run

on quitApps(apps)
	repeat with oneApp in apps
		quit application oneApp
	end repeat
end quitApps

Thank you StefanK,

Thank you for your efforts. I bow in respect. I will try it now.

Oops! Just got called in to work. Probably another 16 hour stint.

I’ll try it later and post my results.

Thanks again,

pw

Do you know, that you can als do it easily with

⌘⇥ (hold ⌘) q q q q.

Well, one $400 Ultra-Quick acting 150 amp semi-conductor fuse (which really ain’t all that fast I guess) and one pair of 200 amp hockey-puck power SCR’s later and I’m back home. Oh yea. And all the wonderful overtime pay. Guess I need to spend it on Applescripting books, eh? Anyway…

I hate keyboard commands. (Not really). Besides, I’d have to put my beer down and like I said I’m lazy.

I tried your script just before I left and it would not build. Don’t remember the error. EOL error I think. (I copied and pasted from your post). Anyway I played around with it and now it works OK. Quite handy too. Just buried to deep in the CM.

To get the script to build and then run I had to change “whose background only is false and name is not “Finder”” to “whose name is not “Finder” and background only is false”
and I also had to define the variable theApps with a “set theApps to result” command after the above statement. I saved it as a “Finder” plugin.

I dabbled with Applescript Studio and Xcode a few years ago and got COMPLETELY burned out on it. The backup application I made wasn’t complete but still worked OK. I was just sick of it. I really hand it to you guys who can talk code like normal people talk in conversation. I’ve been an Electrical/Electronics tech for over 30 years and thats enough.

I may try my hand at making a contextual menu plugin that will let me place the open applications names and a quit all selection just one level down. This would be much quicker and a little more normal looking.

Thanks for all your help.

pwilson