Question

I can't work out how to list all the Applications that a user has placed in the dock.

Is this possible?

Was it helpful?

Solution

Try this. This is a list of the apps a person has that are persistent in the dock. What I've basically done is use system events to read the plist file into an applescript record in the pListItems variable. Then I can use applescript techniques to access the lists and records inside of pListItems.

There's lots of information in com.apple.dock so you can look at the pListItems variable and work your way through it to pull out whatever you need. For example you might want the "|bundle-identifier|" instead of the "|file-label|". Good luck.

set plistpath to (path to preferences folder as text) & "com.apple.dock.plist"

tell application "System Events"
    set plistContents to contents of property list file plistpath
    set pListItems to value of plistContents
end tell
set persistentAppsList to |persistent-apps| of pListItems

set dockAppsList to {}
repeat with thisRecord in persistentAppsList
    set end of dockAppsList to |file-label| of |tile-data| of thisRecord
end repeat

return dockAppsList

OTHER TIPS

Adding on to the response by regulus6633 As suggested, using |bundle-identifier| does make for more reliable results in this script. For example, Evernote will not correctly identify in all AppleScript uses by using the |file-label| property due to both Evernote.app and EvernoteHelper.app having the same short name (CFBundleName).

Additional idea I used this script as a basis for one that start all applications that are permanently placed in the dock ('Keep in dock' option). I removed the dockAppsList array and replaced the second loop to activate all these applications. To avoid having windows splattered all over my screen, I maintain appName and use it to hide them right after activating the application.

To adjust, replace code after the end tell statement with the following:

repeat with thisRecord in |persistent-apps| of pListItems
set appName to |file-label| of |tile-data| of thisRecord
set appID to |bundle-identifier| of |tile-data| of thisRecord
tell application id appID to activate
tell application "Finder" to set visible of process appName to false
end repeat
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top