2017-04-13 187 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