用于复制和重命名的Applescript

问题描述 投票:0回答:2

我正在尝试创建一个 AppleScript 以在重命名文件时将单个文件复制到新位置。我对文件的重命名感到困惑。

我尝试过设置“使用属性”、设置别名,但仍然出现错误。

tell application "Finder"
    set JobName to text returned of (display dialog "Please Enter Crate Name:" default answer "Job_Name")
    set loc to alias "Volumes:MusicExt:_Serato_:Subcrates:"
    set templatefile to alias "Volumes:MusicExt:Serato_Working:crate-template.crate"

    duplicate file templatefile to loc --> with properies {name:JobName}
    duplicate file templatefile to loc --> with properies {name:"10. Pre-CMY.m3u"}
 end tell
duplicates applescript rename
2个回答
1
投票
  • 首先,HFS 路径始终以磁盘名称开头,而不以
    Volumes
    开头。
  • 其次,切勿将
    file
    关键字放在
    alias
    说明符前面

使用 Finder,您需要两个步骤:复制文件,然后重命名。
利用

duplicate
的返回值,即重复的文件。

tell application "Finder"
    set JobName to text returned of (display dialog "Please Enter Crate Name:" default answer "Job_Name")
    -- In this case just HFS string paths are preferable
    set loc to "MusicExt:_Serato_:Subcrates:"
    set templatefile to "MusicExt:Serato_Working:crate-template.crate"

    set duplicatedFile to duplicate file templatefile to folder loc
    set name of duplicatedFile to JobName -- (& ".crate") is there no file extension??
 end tell

注意:

with properties
仅适用于
make
命令。


0
投票

是否可以修改此脚本,以便它提示我为顶级文件夹输入新名称?

我为什么需要这个?因为有时我需要在同一目录中复制文件夹树。就目前情况而言,如果我尝试将其保存到同一目录中,则会引发错误。

蒂亚!

© www.soinside.com 2019 - 2024. All rights reserved.