AppleScript-创建一个变量文件夹,然后使用rsync复制到该位置?

时间:2019-02-06 17:52:43

标签: applescript

我想拥有一个Apple脚本来将用户备份到smb驱动器。

到目前为止,我已经设法在正确的位置创建带有变量的文件夹。这包括日期和当前用户的简短用户名。

我现在正在努力使用rsync将用户文件夹复制到smb上新创建的变量文件夹中。

-- Ask for computer type
set ComputerList to {"macbookair", "macbookpro", "imac", "macmini"}
set ComputerType to choose from list ComputerList with title "Users 
Machine" with prompt "What Type of Machine Does the User Have?" 
default items "macbookair"

-- Looks for Username
set userName to short user name of (system info)

-- Sets path where folder created
set p to alias "link:to:smb:volume:"

-- Sets current date
set d to short date string of (current date)
set FullDate to d

-- Creates the folder
tell application "Finder" to make new folder at p with properties 
{name:FullDate & "_" & userName & "-" & ComputerType}

-- Copies the data
do shell script "rsync -zaP ~/ 
/Volumes/Goes/Here/VARIABLEFOLDERHERE --exclude='Library' -- 
exclude='Public' --exclude='Applications"

1 个答案:

答案 0 :(得分:0)

您可以使用创建文件夹的行的结果。

Shell脚本需要POSIX路径,强烈建议始终使用quoted form of来转义路径

tell application "Finder" 
    set newFolder to make new folder at p with properties {name:FullDate & "_" & userName & "-" & ComputerType}
    set newFolderPOSIX to POSIX path of (newFolder as text)
end tell

do shell script "rsync -zaP ~/" & space & quoted form of newFolderPOSIX & space & "--exclude='Library' --exclude='Public' --exclude='Applications'"