On my Mac, the following script returns 80 apps including “root services”.
Is there a simple way to restrict the list to apps that owns a scripting dictionary?
use framework "Foundation"
use framework "AppKit"
set theWorkspace to current application's NSWorkspace's sharedWorkspace()
set appList to theWorkspace's runningApplications()
set scriptableList to current application's NSMutableArray's array()
repeat with anApp in appList
try
set {theResult, theError} to ((anApp's bundleURL())'s getResourceValue:(reference) forKey:(current application's NSURLApplicationIsScriptableKey) |error|:(missing value))
if theResult as boolean then (scriptableList's addObject:(anApp's localizedName()))
end try
end repeat
scriptableList as list
You’re actually storing the scriptability flag in the variable theError. Try this:
use framework "Foundation"
use framework "AppKit"
set theWorkspace to current application's NSWorkspace's sharedWorkspace()
set appList to theWorkspace's runningApplications()
set scriptableList to current application's NSMutableArray's array()
repeat with anApp in appList
try
set {theResult, isScriptable, theError} to ((anApp's bundleURL())'s getResourceValue:(reference) forKey:(current application's NSURLApplicationIsScriptableKey) |error|:(reference))
if isScriptable as boolean then (scriptableList's addObject:(anApp's localizedName()))
end try
end repeat
scriptableList as list
They’re subtly different, at least here, in that System Events seems to be returning the names of the applications, whereas the ASObjC code is returning the process names as they appear in Activity Monitor.
That looks like a bug in System Events to me, but it might actually be more useful.