Created
July 20, 2023 17:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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