首页 > 解决方案 > AppleScript - 创建一个变量文件夹,然后使用 rsync 复制到该位置?

问题描述

我想要一个将用户备份到 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"

标签: applescript

解决方案


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

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'"

推荐阅读