2014-09-05 31 views
0

我有一個AppleScript的是讓我一個文件對象獲得在AppleScript的一個文件路徑中的所有文件夾 - 這樣我就可以標記它們

我現在想通過所有在其路徑它上面的文件夾中行走(每個文件可能會降低許多級別)併爲它們添加顏色。

到目前爲止,我可以看到有在文件的路徑,但我不知道是什麼類型丟給(它不是一個字符串):

copy path of theFile as string to FileNamesPath 

如果我能得到的每個文件夾,然後我可以應用標籤/標籤使它們成爲一種顏色:

tell application "Finder" to set label index of theFolder to 3 

如何從文件中獲取每個文件夾?

回答

0

得到我使用的父文件夾容器屬性。 例如,我們得到了桌面上的文件:

- 文件夾啓動盤的「用戶」文件夾「USERNAME」的>文件夾「桌面」

要使用此輸出我改變工作它的別名:

- >別名的 「Macintosh HD:用戶:用戶名:桌面」

隨着重複循環,我得到人l父文件夾。停止我你一個stopFolder變量。在這種情況下,用戶文件夾。

tell application "Finder" 
    set stopFolder to POSIX path of the (path to the users folder) 
    set labelFolder to (choose file) 
    set lastParentFolder to (container of labelFolder as alias) 
    repeat 
     if POSIX path of lastParentFolder = stopFolder then return "ready" 
     label index of lastParentFolder # get label index 
     set label index of lastParentFolder to 3 # set new label index 
     set lastParentFolder to (container of lastParentFolder as alias) 
    end repeat 
end tell 

獲取標籤指數

行只顯示在協議原來的標籤索引。

+0

謝謝@sidasa。爲你的答案。 – DEzra 2014-09-11 21:46:52

0

如果你有一個文件或別名對象,像這樣

alias "Macintosh HD:Users:user:Images:1401711772700.jpg"

file "Macintosh HD:Users:user:Images:1401711772700.jpg" 

HFS路徑,你可以試試這個小腳本

tell application "Finder" 
    set labelfolder to (choose file) #or insert file object here 
    repeat 
     set labelfolder to container of labelfolder 
     if labelfolder is startup disk then exit repeat 
     try #labels are disabled on some folders 
      set label index of labelfolder to 3 
     end try 
    end repeat 
end tell 
相關問題