2016-05-19 28 views
0

我試圖從一個文件夾複製到另一個文件夾中的所有文件。 只有當我指定包含驅動器名稱和用戶名的完整路徑時,它纔有效。AppleScript從任何用戶名複製文件到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

回答

2

的相對路徑相當於是

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

((path to library folder from user domain as text) & "Containers:com.apple.iWork.Numbers:Data:Library:Application Support:User Templates:")

+0

謝謝@vadian但如果目標是不是在桌面上,但在用戶庫更深的路徑? – Zeton

+0

這個路徑是確切的:〜/ Library/Containers/com.apple.iWork.Numbers/Data/Library/Application Support/User Templates – Zeton

+0

我更新了答案 – vadian

相關問題