2013-11-24 117 views
2

我已經創建了一個AppleScript,對我很有幫助,並希望能夠自動更改文件夾圖標。用AppleScript更改文件夾的圖標?

該腳本非常簡單,它創建一個文件夾,然後在同一個文件夾中創建一個空文本文件。

下面是腳本:

tell application "Finder" 
    set newfolder to make new folder with properties {name:My Folder} 
    make new file at newfolder with properties {name:"read_me.txt"} 
end tell 

是否有可能自動更改文件夾圖標?

(我自己在同一文件夾中的腳本我的自定義文件夾圖標(.icns),當然)

回答

3

繼承人使用命令行實用程序「操作SetIcon」在此包中找到了解決辦法:http://sourceforge.net/projects/osxutils/

它假定你的腳本,icns文件和新文件夾都在同一個目錄下。

tell application "Finder" 
    set parent_path to ((the container of the (path to me)) as text) 
    set target_folder_path to quoted form of POSIX path of (parent_path & "my folder") 
    set icon_path to quoted form of POSIX path of (parent_path & "icon.icns") 
    do shell script "/usr/local/bin/seticon -d " & icon_path & " " & target_folder_path 
end tell 
+0

謝謝您的幫助!爲了這個工作,我將不得不復制和粘貼在父文件夾中的文件與腳本,是否有可能? – GilbertOOl

+0

當然沒有問題,或者你可以將你的文件夾保存在一個固定的地方,只需使用一個絕對路徑。 tell中的前3行只是處理路徑,do shell腳本是至關重要的部分,您可以傳遞您需要的任何路徑。 – adamh

+0

非常感謝! (請參閱我的個人資料,關於Applescript的另一個問題;-)) – GilbertOOl

相關問題