我正在尝试使用Applescript移动文件,每次运行该应用程序时都会收到错误。 在应用程序的内容中,我有要移动的文件(因此,如果我分发应用程序,用户不必单独下载文件)。 这也是为什么我使用((path to home folder as text)
并添加特定的文件路径的原因。这是我的代码:
set source to ((path to home folder as text) & "/Contents/Resources/finder.jpg")
set source2 to ((path to home folder as text) & "/Contents/Resources/finder@2x.jpg")
set destination to alias "Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources:"
tell application "Finder"
move source to destination with replacing
move source2 to destination with replacing
end tell
附言 我检查了这里几乎所有相关的问题/答案,但没有帮助。
一个简单的
display dialog source
会引导你找到解决方案:
-
path to home folder
将别名返回到您的 HOME 文件夹(Macintosh HD:Users:Your name:)。我想你想要path to me
指向你的应用程序。 -
analias as text
返回一个路径字符串,使用 : 作为分隔符,并附加使用 / 分隔路径组件的部分 -
analias as text
返回一个以 结尾的路径字符串
:如果是目录
摘要:尝试
set source to ((path to me as text) & "Contents:Resources:finder.jpg")
更新:你不能用alias ...
,更好的使用是... as alias
,我想,也许duplicate
在这里更好......
set source to ((path to me as text) & "Contents:Resources:finder.jpg") as alias
set source2 to ((path to me as text) & "Contents:Resources:finder@2x.jpg") as alias
set destination to "Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources:" as alias
tell application "Finder"
duplicate source to destination with replacing
duplicate source2 to destination with replacing
end tell
享受, 迈克尔/汉堡