问题
I can't work out how to list all the Applications that a user has placed in the dock.
Is this possible?
回答1:
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
回答2:
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
来源:https://stackoverflow.com/questions/14245301/can-applescript-list-all-the-applications-placed-in-the-dock