List the running apps with scripting terminology

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

Another solution might be:

tell application "System Events" to set scriptableList to name of application processes whose has scripting terminology is true

Sometimes I’m blind…

:wink:

Yep. That’s what I was using still now.

:wink:

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.