要使用AppleScript复制并重命名文件,可以使用“do shell script”命令与Unix命令组合。下面是一个示例代码:
set sourcePath to POSIX path of (choose file with prompt "选择要复制的文件:")
set targetPath to POSIX path of (choose folder with prompt "选择目标文件夹:")
-- 提取文件名和文件扩展名
set {fileName, fileExtension} to my extractNameAndExtension(sourcePath)
-- 生成新的文件名
set newFileName to "新文件名" & fileExtension
-- 构建目标路径
set destinationPath to targetPath & newFileName
-- 使用Unix命令复制并重命名文件
do shell script "cp " & quoted form of sourcePath & space & quoted form of destinationPath
on extractNameAndExtension(filePath)
set AppleScript's text item delimiters to {"."}
set fileNameWithExtension to last text item of filePath
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to {""}
set nameItems to text items of fileNameWithExtension
set AppleScript's text item delimiters to ""
set fileName to items 1 thru -2 of nameItems as text
set fileExtension to last item of nameItems
return {fileName, "." & fileExtension}
end extractNameAndExtension
这段代码首先使用“choose file”和“choose folder”命令让用户选择要复制的文件和目标文件夹。然后,使用“do shell script”命令和Unix命令“cp”复制并重命名文件。请注意,代码中的“新文件名”是一个示例新文件名,您可以根据需要自行更改。