Shutdown Application with Timer (AsObjC)

One small but cool script I just wrote. Its advantage over the versions already available on the network is that it relieves the user of the need to manually type the application name.


--- Script for when you want to close an application in the future, but you don't want to be bothered to remember to do it
use framework "Foundation"
use scripting additions
property curApp : a reference to current application
property NSWorkspace : a reference to NSWorkspace of curApp
property NSMutableArray : a reference to NSMutableArray of curApp
property NSURLApplicationIsScriptableKey : a reference to NSURLApplicationIsScriptableKey of curApp
property |timeout| : 60 -- minutes

set appList to (NSWorkspace's sharedWorkspace())'s runningApplications()
set appNames to NSMutableArray's array()
repeat with anApp in appList
	try
		set {theResult, theError} to ((anApp's bundleURL())'s getResourceValue:(reference) forKey:NSURLApplicationIsScriptableKey |error|:(missing value))
		if theResult as boolean then (appNames's addObject:(anApp's localizedName()))
	end try
end repeat

set applicationName to choose from list (appNames as list) ¬
	with prompt "Choose application you want to shut down after   " & |timeout| & "  minutes(s)"
if applicationName is false then return
set applicationName to item 1 of applicationName

delay minutes * |timeout|
tell application applicationName to quit