我知道这里已经涵盖了这个错误,但我现在一直在搜索答案,当我认为我已经破解它时,我最终在其他地方破解了代码。
我正在尝试在Xcode中运行AppleScript来备份设置网络计算机上的文件夹。
我遇到的问题是备份是用日期标记的,并且位于用户桌面上的子文件夹中。 我试图避免使用硬POSIX路径使最终的应用程序通用。 我找到的所有解决方案都没有考虑到这一点。
我为凌乱的代码道歉,但我仍然在学习AppleScript,因此最终将不同的代码段散列在一起。我的代码是
set catFolder to "Catalyst AA"
set bckup to "Backups"
set myDesktop to path to desktop folder as alias
set main_folder to ((path to desktop folder) & "Backups") as string
tell application "Finder"
if not (exists folder (bckup) in myDesktop) then
set main_folder to (make new folder at desktop with properties {name:bckup}) as alias
else
if not (exists folder (catFolder) in main_folder) then
set cat_folder to (make new folder at folder main_folder with properties {name:catFolder}) as alias
end if
end if
end tell
try
mount volume "afp://10.0.0.1/Content SSD AA/Catalyst/Catalyst 4.40_m373_HD"
set d to (year of (current date) as text) & "-" & (month of (current date) as integer as text) & "-" & (day of (current date) as text) & "-" & (time string of (current date))
tell application "Finder"
set f to make new folder at POSIX file "~/Desktop/Backups/Catalyst AA" with properties {name:d}
duplicate POSIX file "/Volumes/Content SSD AA/Catalyst" to f
end tell
try
tell application "Finder"
eject disk "Content SSD AA"
end tell
end try
end try
错误文件是
tell application "Finder"
path to desktop as alias
--> alias "Macintosh HD:Users:ben:Desktop:"
path to desktop
--> alias "Macintosh HD:Users:ben:Desktop:"
exists folder "Backups" of alias "Macintosh HD:Users:ben:Desktop:"
--> true
Result:
error "Can’t make \"Catalyst AA\" into type integer." number -1700 from "Catalyst AA" to integer
如果有人能指出我出错的地方,我感激不尽。
感谢您的时间
本
答案 0 :(得分:0)
试试这个:
set folderPath to POSIX path of (path to desktop as text) & "Backups/Catalyst AA"
do shell script "mkdir -p " & quoted form of folderPath
try
mount volume "afp://10.0.0.1/Content SSD AA/Catalyst/Catalyst 4.40_m373_HD"
set d to (year of (current date) as text) & "-" & (month of (current date) as integer as text) & "-" & (day of (current date) as text) & "-" & (time string of (current date))
tell application "Finder"
set f to make new folder at POSIX file folderPath with properties {name:d}
duplicate POSIX file "/Users/unimac/Desktop/output.csv" to f
end tell
try
tell application "Finder"
eject disk "Content SSD AA"
end tell
end try
end try