2012-02-27 113 views
0

這個applet代碼在單個選定文件夾內創建特定文件夾結構,或者在單擊該小程序時在Finder中打開文件夾。如果選擇多個文件夾,它會中斷。有多種方式可以讓這個腳本在多個文件夾被選中時工作嗎?Applescript:在多個文件夾中創建新的文件夾結構

property archivesFolder : "Archives" 

property imagesFolder : "Images" 

property proofreadFolder : "Proofreading" 

property proofFolder : "Proofs" 

property sourceFolder : "Source" 

try 
    tell application "Finder" to set theLocation to the selection as alias 
on error 
    tell application "Finder" to set theLocation to (folder of the front window as alias) 
end try 

tell application "Finder" 

    if not (exists folder archivesFolder of theLocation) then 
     make new folder at theLocation with properties {name:archivesFolder} 
    end if 

    if not (exists folder imagesFolder of theLocation) then 
     make new folder at theLocation with properties {name:imagesFolder} 
    end if 

    if not (exists folder proofreadFolder of theLocation) then 
     make new folder at theLocation with properties {name:proofreadFolder} 
    end if 

    if not (exists folder proofFolder of theLocation) then 
     make new folder at theLocation with properties {name:proofFolder} 
    end if 

    if not (exists folder sourceFolder of theLocation) then 
     make new folder at theLocation with properties {name:sourceFolder} 
    end if 

end tell 

回答

2

試試這個:

property folderNames : {"Archives", "Images", "Proofreading", "Proofs", "Source"} 

tell application "Finder" 
set selectedFolders to selection 
if (count of selectedFolders) > 0 then 
    repeat with aFolder in selectedFolders 
     set theLocation to aFolder as string 
     repeat with newFolder in folderNames 
      try 
       make new folder at theLocation with properties {name:"" & newFolder & ""} 
      end try 
     end repeat 
    end repeat 
else 
    set theLocation to (target of front window) as string 
    repeat with newFolder in folderNames 
     try 
      make new folder at theLocation with properties {name:"" & newFolder & ""} 
     end try 
    end repeat 
end if 
end tell 
+0

偉大的作品,但失去了如果沒有被選中創造了當前的取景器窗口這些文件夾的功能。 – user1231499 2012-02-27 19:10:34

+0

@ user1231499在這裏你去:https://gist.github.com/1932089 – fanaugen 2012-02-28 11:48:14

+0

@fanaugen張貼的答案不工作?你能幫我複製一個錯誤嗎? – adayzdone 2012-02-28 13:15:29

相關問題