1

我正在尝试使用 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

ps 我几乎检查了这里的所有相关问题/答案,但没有任何帮助。

4

1 回答 1

1

一个简单display dialog source的方法会引导您找到解决方案:

  1. path to home folder返回您的HOME文件夹的别名(Macintosh HD:Users:your name:)。我认为您想要的是指向您的应用程序。path to me
  2. analias as text使用:作为分隔符返回路径字符串,并附加使用/来分隔路径组件的部分
  3. 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

享受,迈克尔/汉堡

于 2015-03-17T08:04:19.017 回答