Applescript 用任意用户名将文件从a复制到b

Applescript 用任意用户名将文件从a复制到b,applescript,relative-path,file-copying,Applescript,Relative Path,File Copying,我正在尝试将所有文件从一个文件夹复制到另一个文件夹。 仅当我指定完整路径(包括驱动器名称和用户名)时,此操作才有效 这项工作: tell application "Finder" set a to folder "Macintosh HD:Users:Michael:Desktop:Files:" set b to folder "Macintosh HD:Users:Michael:Desktop:Copies" duplicate every file of a to b 结束语 但我想让

我正在尝试将所有文件从一个文件夹复制到另一个文件夹。 仅当我指定完整路径(包括驱动器名称和用户名)时,此操作才有效

这项工作:

tell application "Finder"
set a to folder "Macintosh HD:Users:Michael:Desktop:Files:"
set b to folder "Macintosh HD:Users:Michael:Desktop:Copies"
duplicate every file of a to b
结束语

但我想让它与任何硬盘命名和用户名兼容。
所以我在寻找一个相对路径,相当于
~:Desktop

相对路径等价于

set desktopFolder to path to desktop
tell application "Finder"
    set a to folder "Files:" of desktopFolder
    set b to folder "Copies:" of desktopFolder
    duplicate every file of a to b
end tell
但是Finder有一个属性
desktop
,它总是指向当前用户的桌面文件夹

tell application "Finder"
    set a to folder "Files:" of desktop
    set b to folder "Copies:" of desktop
    duplicate every file of a to b
end tell
更简短的是,当前用户的桌面文件夹是Finder的“根”文件夹

tell application "Finder"
    duplicate every file of folder "Files" to folder "Copies"
end tell
编辑:

相当于

~/Library/Containers/com.apple.iWork.Numbers/Data/Library/Application Support/User Templates


((以文本形式从用户域到库文件夹的路径)和“Containers:com.apple.iWork.number:Data:library:Application Support:user Templates:”)

相对路径等效为

set desktopFolder to path to desktop
tell application "Finder"
    set a to folder "Files:" of desktopFolder
    set b to folder "Copies:" of desktopFolder
    duplicate every file of a to b
end tell
但是Finder有一个属性
desktop
,它总是指向当前用户的桌面文件夹

tell application "Finder"
    set a to folder "Files:" of desktop
    set b to folder "Copies:" of desktop
    duplicate every file of a to b
end tell
更简短的是,当前用户的桌面文件夹是Finder的“根”文件夹

tell application "Finder"
    duplicate every file of folder "Files" to folder "Copies"
end tell
编辑:

相当于

~/Library/Containers/com.apple.iWork.Numbers/Data/Library/Application Support/User Templates


((以文本形式从用户域到库文件夹的路径)和“Containers:com.apple.iWork.number:Data:library:Application Support:user Templates:”)

谢谢@vadian,但是如果目的地不在桌面上,而是在用户库中的更深路径中呢?确切地说,这条路径:~/library/Containers/com.apple.iWork.Numbers/Data/library/Application Support/user templatesHank you@vadian但是如果目的地不在桌面上,而是在用户库中的更深路径中呢确切路径:~/Library/Containers/com.apple.iWork.Numbers/Data/Library/Application Support/User Templates