【发布时间】:2023-03-14 23:48:01
【问题描述】:
我不知道如何列出用户放置在 Dock 中的所有应用程序。
这可能吗?
【问题讨论】:
标签: applescript dock
我不知道如何列出用户放置在 Dock 中的所有应用程序。
这可能吗?
【问题讨论】:
标签: applescript dock
试试这个。这是一个人拥有的在 Dock 中持久存在的应用程序的列表。我基本上所做的是使用系统事件将 plist 文件读入 pListItems 变量中的 applescript 记录。然后我可以使用 applescript 技术来访问 pListItems 中的列表和记录。
com.apple.dock 中有很多信息,因此您可以查看 pListItems 变量并按自己的方式处理以提取您需要的任何内容。例如,您可能需要“|bundle-identifier|”而不是“|文件标签|”。祝你好运。
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
【讨论】:
添加到 regulus6633 的响应 正如建议的那样,使用 |bundle-identifier| 确实可以在此脚本中获得更可靠的结果。例如,由于 Evernote.app 和 EvernoteHelper.app 具有相同的短名称 (CFBundleName),Evernote 无法在所有 AppleScript 使用中通过使用 |file-label| 属性正确识别。
其他想法我将此脚本用作启动永久放置在 Dock 中的所有应用程序的基础(“保持在 Dock 中”选项)。我删除了 dockAppsList 数组并替换了第二个循环来激活所有这些应用程序。为了避免窗口溅到我的屏幕上,我维护appName 并在激活应用程序后使用它来隐藏它们。
要进行调整,请将end tell 语句后的代码替换为以下内容:
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
【讨论】: