veadar
7/24/2017 - 11:34 AM

kill app.scpt

-- kill_aProc from http://piyocast.com/as/archives/610

property excludeStrings : {"Google Chrome Helper", "Google Chrome Helper EH", "com.apple.WebKit.WebContent"}

tell application "System Events"
	set pre_appList to name of (application processes) whose background only is false
end tell

set appList to excludeList(pre_appList, excludeStrings)

choose from list appList with multiple selections allowed

if result is not false then
	
	set killAppList to result
	
	repeat with i from 1 to length of killAppList
		kill_aProc(item i of killAppList) of me
	end repeat
	
end if

on excludeList(pre_appList, excludeStrings)
	set appList to {}
	
	repeat with i from 1 to length of pre_appList
		if excludeStrings does not contain item i of pre_appList then
			
			set end of appList to item i of pre_appList
		end if
	end repeat
	
	return appList
end excludeList

--kill_aProc("InDesign CS3") of me

on kill_aProc(aProcName)
	tell application "System Events"
		set procList to every process whose name contains aProcName
		if procList is not equal to {} then
			set aProc to contents of first item of procList
			tell aProc
				set anID to unix id
			end tell
			do shell script "kill -9 " & (anID as string)
		end if
	end tell
end kill_aProc