runningappinfo(
Application
)

The runningappinfo( function returns information about applications that are currently running on this computer.


Parameters

This function has one parameter:

application – application of interest. This can be either the bundle identifier of the application (text), or the process ID of the application (numeric). If this parameter is omitted, information about all running applications will be returned.


Description

This function returns information about applications that are currently running on this computer. The information is returned in JSON format.

To use this function you will usually need to know the Bundle Identifier of the application you are interested in. The bundle identifier is the unique ID for an app, this ID is assigned by the author of the app and doesn’t change even if the name of the app is renamed or localized. For example, the bundle id of Preview is com.apple.Preview whether you are in the United States, Italy, or Japan.

Unfortunately, Apple doesn’t make it easy to find out what the bundle ID of an application is. If you know how to do it, you can dig into the app’s plist with a text editor to find it, but probably the easiest method is to use Terminal.app, then type this script in:

osascript -e 'id of app "Preview"'

Terminal.app will reply with the id of the app, in this case com.apple.Preview. Substitute the app you are interested in instead of the name Preview when you type the script into the terminal.

Once you know the bundle id, you can use the runninaappinfo( function to find out if that app is currently running. If it is, the function will return information about the app, if not, it will return empty text. For example, this code will test to see if Preview is currently running on your computer.

if runningappinfo("com.apple.Preview")<>""
    ... do something now that we know that Preview is running
endif

In the example above, we’re not really interested in the detailed information about the app, just whether it is running or not. But the runninaappinfo( function returns much more information about that. On my system right now, the code

runningappinfo("com.apple.Preview")

returns something like this (it’s actually all on one line, but split into multiple lines below so that it will fit in this help window):

{"identifier":"com.apple.Preview",
"name":"Preview",
"path":"/Applications/Preview.app",
"executable":"/Applications/Preview.app/Contents/MacOS/Preview",
"processid":97652,
"active":false,
"hidden":false,
"menubar":false}

As you can see, 8 items about Preview are returned:

The returned information is in JSON format, which you can convert to a Panorama dictionary with the jsonimport( function. From the dictionary you can easily extract any item you want. This example will open the Finder window that contains the running copy of Preview on your system, even if it has been moved to a non-standard folder.

let previewPath = getdictionaryvalue(jsonimport(runningappinfo("com.apple.Preview")),"path")
revealinfinder previewPath

Identifying an App by Process ID

If you happen to know the process id of the application you are interested in, you can use that instead of the bundle identifier.

runningappinfo(97652)

Finding Out About All Running Applications

To find out about all running applications, simply omit the parameter, for example:

runningappinfo()

This will return one line for every running app. You’ll probably be shocked at how many apps are running on your system, many of which you have never heard of. I’ve massively redacted the list below, there were 212 apps running on my system at the moment when this documentation was being written.

{"identifier":"com.apple.Terminal", "name":"Terminal", "path":"/Applications/Utilities/Terminal.app", "executable":"/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal", "processid":14542, "active":false, "hidden":false, "menubar":false}
{"identifier":"com.apple.iChat", "name":"Messages", "path":"/Applications/Messages.app", "executable":"/Applications/Messages.app/Contents/MacOS/Messages", "processid":14683, "active":false, "hidden":false, "menubar":false}
{"identifier":"com.apple.WebKit.WebContent", "name":"Safari Web Content", "path":"/System/Library/StagedFrameworks/Safari/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.WebContent.xpc", "executable":"/System/Library/StagedFrameworks/Safari/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.WebContent.xpc/Contents/MacOS/com.apple.WebKit.WebContent", "processid":34540, "active":false, "hidden":false, "menubar":false}
{"identifier":"com.google.Chrome", "name":"Google Chrome", "path":"/Applications/3rd Party Apps/Google Chrome.app", "executable":"/Applications/3rd Party Apps/Google Chrome.app/Contents/MacOS/Google Chrome", "processid":34565, "active":false, "hidden":false, "menubar":false}
...
...
...
{"identifier":"com.apple.Preview", "name":"Preview", "path":"/Applications/Preview.app", "executable":"/Applications/Preview.app/Contents/MacOS/Preview", "processid":97652, "active":false, "hidden":false, "menubar":false}
{"identifier":"com.provue.PanoramaX", "name":"PanoramaX", "path":"/Users/jimrea/Library/Developer/Xcode/DerivedData/PanoramaX-ehjikolcvqyxxxhfuplltldupnfg/Build/Products/Debug/PanoramaX.app", "executable":"/Users/jimrea/Library/Developer/Xcode/DerivedData/PanoramaX-ehjikolcvqyxxxhfuplltldupnfg/Build/Products/Debug/PanoramaX.app/Contents/MacOS/PanoramaX", "processid":34789, "active":true, "hidden":false, "menubar":true}

Each line contains a JSON record, but the overall result is not a JSON array, instead it is a Panorama text array of JSON records. It’s much easier for Panorama code to handle a text array than a JSON array. However, if you need to convert this into a full JSON array, it can be done with this formula:

"[ "+arrayfilter(runningappinfo(),cr(),{import()+","})+" ]"

See Also


History

VersionStatusNotes
10.2NewNew in this version.