2017-04-13 190 views
0

我試圖創建一個腳本,將模板文件夾複製到當前的finder窗口,然後根據對話框輸入重命名新文件夾和其中的一些文件。Applescript - 重複文件夾,然後重命名和重命名文件

到目前爲止,我已經知道它可以將文件夾(從選區)複製到當前查找程序窗口並對其進行重命名。但我無法得到它,然後重命名它內的文件。

下面的代碼 -

property A : POSIX file "/BLOCKED OUT FOR PRIVACY/" as alias 
property B : POSIX file "/BLOCKED OUT FOR PRIVACY/" as alias 
property C : POSIX file "/BLOCKED OUT FOR PRIVACY/" as alias 
property D : POSIX file "/BLOCKED OUT FOR PRIVACY/" as alias 

tell application "Finder" 
set x to target of window 1 as alias 
end tell 

set JobName to text returned of (display dialog "Enter Folder Name:" default answer "Template Folder") 

set CATno to text returned of (display dialog "Enter CAT number:" default answer "CMXX0000") 

set optionList to {"OPTION 1", "OPTION 2", "OPTION 3", "OPTION 4"} 

set chosenFolder to choose from list optionList with prompt "Choose a Folder" 

set chosenFolder to chosenFolder's item 1 

if chosenFolder is "OPTION 1" then 

tell application "Finder" 
    set FolderCopy to duplicate B to x 
    set the name of FolderCopy to JobName 
    set Insert to (POSIX path of (path to home folder)) & "DVD Insert Artwork/Indesign Project File/_Insert.indd" as POSIX file 
    set the name of Insert to JobName & CATno 
end tell 
end if 

我剪了POSIX文件路徑,因爲它們包含我的公司名稱和等。我也忽略了其他部分,因爲它們基本上是第一部分的重複部分。

set Insert to (POSIX path of (path to home folder)) & "DVD Insert Artwork/Indesign Project File/_Insert.indd" as POSIX file 
set the name of Insert to JobName & CATno 

這是給我麻煩的部分。它應該是重命名在新複製的文件夾內的文件到CATno對話框中輸入的內容+「_Insert.indd」

任何幫助,非常感謝!

謝謝:)

回答

1

我不確定,但是您的意思是?

tell application "Finder" 
    set FolderCopy to duplicate B to x 
    set insertFile to file "_Insert.indd" of FolderCopy 
    set the name of FolderCopy to JobName 
    set name of insertFile to (JobName & CATno & "_Insert.indd") 
end tell 

從重複的文件夾中獲取對設計文件的引用。

+0

感謝您的建議。然而,這將返回一個錯誤 - 「Finder得到一個錯誤:文件夾」Air.Giraffe「的文件夾」下載「的文件夾」新建「文件夾」模板文件夾 - HIDDEN「的文件」_Insert.indd「用戶「(-1728)」我正在重命名的文件位於複製文件夾的幾個子文件夾中,這可能是問題所在? – Airgiraffe

+0

您需要指定文件的完整路徑(以冒號分隔),例如'set insertFile to file((FolderCopy as text)&「subfolder1:subfolder2:_Insert.indd」)'。由於您的問題不包含任何有關文件夾層次結構的信息,因此我不能更準確。 – vadian

+0

這工作!謝謝。但我確實必須將「將FolderCopy的名稱設置爲JobName」。 – Airgiraffe