Search code examples
macosapplescript

AppleScript to get the bundle id of a process that is not an App


I am using zathura PDF viewer on macOS. It was installed using brew. This is not a full-blown app (in that, there is no app in /Applications; I can only start the application from the terminal). When I start Zathura, it becomes a process with the name zathura. I am using Amethyst window manager and I want to find the application identifier of zathura to allow Amethyst to tile zathura windows.

I have tried running the following:

osascript -e 'id of app "zathura"'

But it says 0:2: execution error: Can’t get application "zathura"..

Is there a way with AppleScript that I can get the identifier of a process that is not considered an "app"? In this case, the process zathura and what its identifier is?

When using Amethyst with the default behaviour (tile everything except those I tell you not to), it can tile zathura windows just fine. When I switch to use "don't tile everything except those I tell you", so now I have to provide a list of apps that Amethyst will tile, I can't seem to find the "identifier" of zathura to tell Amethyst to tile it.


Solution

  • When I start Zathura, it becomes a process with the name zathura

    If this is correct, then:

    tell application id "com.apple.SystemEvents" to get the ¬
            bundle identifier of the process named "zathura"
    

    If it has a bundle identifier (it probably does), then this will return it; otherwise, it'll return missing value.

    I'm not familiar with Amethyst so don't know what technique it uses to target windows. You're not clear on how Amethyst expects you to reference applications you pass it, and although it might not be an application in the sense that you described, it might still be possible to resolve an AppleScript application class object using the bundle identifer:

    tell application id "com.apple.SystemEvents" to set ZathuraID ¬
            to the bundle identifier of the process named "zathura"
    
    try
            set ZathuraApp to the application id ZathuraID
    on error
            set ZathuraApp to false
    end try
    

    Many processes that aren't part of the typical application bundles that we most commonly think of as the archetypal macOS application will resolve an application class object perfectly fine, and, while a small proportion of these will be inert (you won't be able to enumerate any properties or pass it through to a command to do something useful with it), a very decent proportion of them can be utilised, e.g.:

    return the path to the ZathuraApp
    

    ADDENDUM: PROOF OF CONCEPT

    Here's a list of file paths for all the processes running on my machine that:

    1. have bundle identifiers; and
    2. resolve to an AppleScript application class object by way of its bundle identifier; and
    3. the path to command can successfully make use of its application object reference in order to return a file path to the progenitor.

    Some of them will undoubtedly be surprising:

    /System/Library/CoreServices/loginwindow.app/
    /System/Library/CoreServices/ControlStrip.app/
    /System/Library/CoreServices/WiFiAgent.app/
    /System/Library/CoreServices/Keychain Circle Notification.app/
    /System/Library/PrivateFrameworks/UniversalAccess.framework/Versions/A/Resources/AXVisualSupportAgent.app/
    /System/Library/CoreServices/talagent
    /System/Library/CoreServices/NotificationCenter.app/
    /System/Library/PrivateFrameworks/AccessibilitySupport.framework/Versions/A/Resources/AccessibilityVisualsAgent.app/
    /System/Library/Input Methods/DictationIM.app/
    /System/Library/CoreServices/TextInputSwitcher.app/
    /System/Library/PrivateFrameworks/SoftwareUpdate.framework/Versions/A/Resources/SoftwareUpdateNotificationManager.app/
    /System/Library/Input Methods/EmojiFunctionRowIM.app/Contents/PlugIns/EmojiFunctionRowIM_Extension.appex/
    /System/Library/CoreServices/CoreLocationAgent.app/
    /System/Library/CoreServices/CoreServicesUIAgent.app/
    /System/Library/CoreServices/LocationMenu.app/
    /System/Library/CoreServices/Spotlight.app/
    /Users/CK/Applications/Transmission.app/
    /System/Library/CoreServices/SystemUIServer.app/
    /System/Library/CoreServices/ControlCenter.app/
    /System/Library/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc/
    /System/Library/CoreServices/Finder.app/
    /Applications/Surfshark.app/Contents/PlugIns/Surfshark Finder Extension.appex/
    /Users/CK/Applications/Resilio Sync.app/Contents/PlugIns/FinderExtension.appex/
    /System/Library/Input Methods/PressAndHold.app/Contents/PlugIns/PAH_Extension.appex/
    /System/Library/CoreServices/Dock.app/Contents/XPCServices/com.apple.dock.extra.xpc/
    /System/Library/CoreServices/TextInputMenuAgent.app/
    /System/Library/CoreServices/AirPlayUIAgent.app/
    /System/Library/CoreServices/Siri.app/
    /System/Library/CoreServices/FolderActionsDispatcher.app/
    /Applications/AppCleaner.app/Contents/Library/LoginItems/AppCleaner SmartDelete.app/
    /Applications/Velja.app/
    /Applications/One Thing.app/
    /Users/CK/Applications/Hammerspoon.app/
    /System/Library/CoreServices/Shortcuts Events.app/
    /Library/Application Support/org.pqrs/Karabiner-Elements/Karabiner-NotificationWindow.app/
    /Library/Application Support/org.pqrs/Karabiner-Elements/Karabiner-Menu.app/
    /System/Library/CoreServices/Siri.app/Contents/XPCServices/SiriNCService.xpc/
    /System/Library/CoreServices/PowerChime.app/
    /Users/CK/Applications/iTerm.app/
    /System/Library/Frameworks/LocalAuthentication.framework/Support/coreautha.bundle/
    /System/Library/CoreServices/OSDUIHelper.app/
    /System/Library/Frameworks/AppKit.framework/Versions/C/XPCServices/com.apple.appkit.xpc.openAndSavePanelService.xpc/
    /System/Library/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc/
    /Users/CK/Applications/Resilio Sync.app/Contents/PlugIns/FinderExtension.appex/
    /Applications/Surfshark.app/Contents/PlugIns/Surfshark Finder Extension.appex/
    /System/Library/PrivateFrameworks/Noticeboard.framework/Versions/A/Resources/nbagent.app/
    /System/Library/PrivateFrameworks/WorkflowKit.framework/XPCServices/ShortcutsViewService.xpc/
    /System/Library/CoreServices/Dock.app/Contents/XPCServices/DockHelper.xpc/
    /System/Library/CoreServices/UserNotificationCenter.app/
    /System/Library/PrivateFrameworks/UniversalAccess.framework/Versions/A/Resources/universalAccessAuthWarn.app/
    /System/Applications/Mail.app/
    /Users/CK/Applications/Raycast.app/
    /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/printtool
    /System/Applications/Utilities/Script Editor.app/
    /System/Library/Frameworks/AppKit.framework/Versions/C/XPCServices/com.apple.appkit.xpc.openAndSavePanelService.xpc/
    /System/Library/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc/
    /Users/CK/Applications/Resilio Sync.app/Contents/PlugIns/FinderExtension.appex/
    /Applications/Surfshark.app/Contents/PlugIns/Surfshark Finder Extension.appex/
    /Users/CK/Applications/Arc.app/
    /System/Library/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc/
    /System/Library/CoreServices/NowPlayingTouchUI.app/
    /System/Library/Frameworks/AppKit.framework/Versions/C/XPCServices/com.apple.appkit.xpc.openAndSavePanelService.xpc/
    /System/Library/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc/
    /Users/CK/Applications/Resilio Sync.app/Contents/PlugIns/FinderExtension.appex/
    /Applications/Surfshark.app/Contents/PlugIns/Surfshark Finder Extension.appex/
    /System/Applications/Shortcuts.app/
    /Users/CK/Applications/Signal.app/
    /System/Library/Frameworks/AppKit.framework/Versions/C/XPCServices/com.apple.appkit.xpc.openAndSavePanelService.xpc/
    /System/Library/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc/
    /Users/CK/Applications/Resilio Sync.app/Contents/PlugIns/FinderExtension.appex/
    /Applications/Surfshark.app/Contents/PlugIns/Surfshark Finder Extension.appex/
    /System/Library/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc/
    /Applications/zoom.us.app/
    /Applications/zoom.us.app/Contents/Frameworks/caphost.app/
    /System/Library/PrivateFrameworks/Lookup.framework/Versions/A/XPCServices/LookupViewService.xpc/
    /System/Library/PrivateFrameworks/WorkflowKit.framework/XPCServices/MacHelper.xpc/
    /System/Library/PrivateFrameworks/Lookup.framework/Versions/A/XPCServices/LookupViewService.xpc/
    /System/Library/CoreServices/System Events.app/