applescript - 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"
解决方案
您可以使用创建文件夹的行的结果。
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'"
推荐阅读
- amazon-web-services - AWS 上的 Kubernetes 有多个账户?
- python - 如果 tkinter 窗口中有很多标签,如何单独识别它们?
- flutter - 如何在颤振中创建自定义弹出菜单
- c# - Linq to Entities 查询结果到十进制变量
- java - 将整个地图转换/展平为列表的最有效方法(键和值一起,而不是分开)
- ios - 无法将 kotlin 接口的快速实现传递给 kotlin 本机
- spring - 在springBoot中使用参数值记录Hibernate查询
- c# - 从 msi 文件中选择行的问题
- wpf - 如何将 TextBox (VIEW) 的 Text 属性绑定到变量 (在 VIEWMODEL 中)
- oracle - 在 Oracle Kubernetes 集群和对象存储上设置 Spinnaker