Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SKaplanOfficial/6efd39f7bd66a7286817b8e8152e2e35 to your computer and use it in GitHub Desktop.
Save SKaplanOfficial/6efd39f7bd66a7286817b8e8152e2e35 to your computer and use it in GitHub Desktop.
AppleScriptObjC script to get a list of the currently installed applications using a Spotlight search.
use framework "Foundation"
property ca : current application
property theResult : ""
property query : missing value
try
set result to ""
ca's NSNotificationCenter's defaultCenter's addObserver:me selector:"queryDidFinish:" |name|:"NSMetadataQueryDidFinishGatheringNotification" object:(missing value)
set predicate to ca's NSPredicate's predicateWithFormat:"kMDItemContentType == 'com.apple.application-bundle'"
set query to ca's NSMetadataQuery's alloc()'s init()
query's setPredicate:predicate
query's setSearchScopes:["/Applications", "/Users/"]
query's startQuery()
repeat while theResult is ""
delay 0.1
end repeat
return text 1 thru ((length of theResult) - 2) of theResult
end try
on queryDidFinish:theNotification
global result
set queryResults to theNotification's object()'s results()
set internalResult to ""
repeat with object in queryResults
set itemName to (object's valueForAttribute:("kMDItemFSName")) as text
set appName to (text 1 thru ((length of itemName) - 4) of itemName)
if appName does not contain "." and appName does not contain "_" and appName does not end with "Agent" and appName does not end with "Assistant" then
set internalResult to internalResult & appName & ", "
end if
end repeat
set theResult to internalResult
end queryDidFinish:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment