2013-01-09 21 views

回答

2

試試這個。這是一個人在碼頭中持久存在的應用程序列表。我基本上所做的就是使用系統事件將plist文件讀入pListItems變量的applescript記錄中。然後我可以使用applescript技術訪問pListItems中的列表和記錄。

com.apple.dock中有很多信息,因此您可以查看pListItems變量並按照自己的方式通過它來取出您需要的任何內容。例如,您可能需要「| bundle-identifier |」而不是「| file-label |」。祝你好運。

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 
+0

真棒。這正是我想要的。謝謝。 – dompardoe

2

添加到由regulus6633作爲響應的建議,使用|bundle-identifier|確實讓在這個腳本更可靠的結果。例如,由於Evernote.app和EvernoteHelper.app具有相同的短名稱(CFBundleName),因此Evernote不會正確識別所有AppleScript使用中的|file-label|屬性。

其他想法我用這個腳本作爲啓動永久放置在碼頭中的所有應用程序('Keep in 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 
相關問題