Saturday, January 16, 2021

#1 2021-01-13 02:46:21 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 594

NSWorkspace runningApplications

This examples use NSWorkspace to get information about runningApplications.

Applescript:

use framework "AppKit"

log runningApplicationsLocalizedName()
log runningApplicationsBundleIdentifier()
log runningApplicationsBundleURL()
log runningApplicationsExecutableURL()
log runningApplicationsLaunchDate()

on runningApplicationsBundleIdentifier()
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   set theList to {}
   repeat with anApp in workspace
       set theItem to anApp's bundleIdentifier() as text
       copy theItem to end of theList
   end repeat
   return theList
end runningApplicationsBundleIdentifier

on runningApplicationsBundleURL()
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   set theList to {}
   repeat with anApp in workspace
       set theItem to anApp's bundleURL()'s |path|() as text
       copy theItem to end of theList
   end repeat
   return theList
end runningApplicationsBundleURL

on runningApplicationsExecutableURL()
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   set theList to {}
   repeat with anApp in workspace
       set theItem to anApp's executableURL()'s |path|() as text
       copy theItem to end of theList
   end repeat
   return theList
end runningApplicationsExecutableURL

on runningApplicationsLaunchDate()
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   set theList to {}
   repeat with anApp in workspace
       set theItem to anApp's launchDate() as list
       copy theItem to end of theList
   end repeat
   return theList
end runningApplicationsLaunchDate

on runningApplicationsLocalizedName()
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   set theList to {}
   repeat with anApp in workspace
       set theItem to anApp's localizedName() as text
       copy theItem to end of theList
   end repeat
   return theList
end runningApplicationsLocalizedName

Choose PID and it will return bundleURL path.
https://developer.apple.com/documentati … guage=objc

Applescript:

use framework "AppKit"
use scripting additions

runningApplicationsProcessIdentifierWithPath()

on runningApplicationsProcessIdentifierWithPath()
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   set theList to {}
   repeat with anApp in workspace
       set theItem to anApp's processIdentifier() as text
       copy theItem to end of theList
   end repeat
   set theProcessID to (choose from list theList) as text
   set theApp to current application's NSRunningApplication's runningApplicationWithProcessIdentifier:theProcessID
   return theApp's bundleURL()'s |path| as text
end runningApplicationsProcessIdentifierWithPath

Input bundleIdentifier, return a string

Applescript:

use framework "AppKit"

my runningApplicationsWithBundleIdentifier:"com.apple.Terminal"

on runningApplicationsWithBundleIdentifier:_bundleIdentifier
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   repeat with anApp in workspace
       if _bundleIdentifier is (anApp's bundleIdentifier() as text) then
           set theString to (anApp's localizedName() as text) & space
           set theString to theString & (anApp's bundleURL()'s |path|() as text) & space
           set theString to theString & (anApp's launchDate() as list) & space
           set theString to theString & (anApp's isHidden() as boolean)
       end if
   end repeat
   return theString
end runningApplicationsWithBundleIdentifier:

Input bundleIdentifier, return a list.

Applescript:

use framework "AppKit"

my runningApplicationsWithBundleIdentifier:"com.apple.Terminal"

on runningApplicationsWithBundleIdentifier:_bundleIdentifier
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   repeat with anApp in workspace
       if _bundleIdentifier is (anApp's bundleIdentifier() as text) then
           set theName to (anApp's localizedName() as text)
           set theBundleURL to (anApp's bundleURL()'s |path|() as text)
           set theLaunchDate to (anApp's launchDate() as list)
           set theHidden to (anApp's isHidden() as boolean)
       end if
   end repeat
   return {theName, theBundleURL, theLaunchDate, theHidden}
end runningApplicationsWithBundleIdentifier:

With Shane's Myriad Tables Lib

Applescript:

use framework "AppKit"
use script "Myriad Tables Lib" version "1.0.9"

my runningApplicationsWithBundleIdentifier:"com.apple.Terminal"

on runningApplicationsWithBundleIdentifier:_bundleIdentifier
   set workspace to (current application's NSWorkspace's sharedWorkspace)'s runningApplications()
   repeat with anApp in workspace
       if _bundleIdentifier is (anApp's bundleIdentifier() as text) then
           set theName to (anApp's localizedName() as text)
           set theBundleURL to (anApp's bundleURL()'s |path|() as text)
           set theLaunchDate to (anApp's launchDate() as list)
           set theHidden to (anApp's isHidden() as boolean)
       end if
   end repeat
   set theData to swap columns and rows in {theName as list, theBundleURL as list, theLaunchDate as list, theHidden as list}
   set theTable to make new table with data theData column headings {"Name", "Location", "Date", "Hidden"}
   modify table theTable with alternate backgrounds
   display table theTable
end runningApplicationsWithBundleIdentifier:

Last edited by Fredrik71 (2021-01-14 04:19:20 am)


The purpose to study someone else art is not to add, its to make less more.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)