【问题标题】:Apple Script: Copy file (being selected from prompt) to another locationApple Script:将文件(从提示中选择)复制到另一个位置
【发布时间】:2021-07-30 11:42:22
【问题描述】:

我正在为我的 Apple 脚本而苦苦挣扎。我要求选择一个文件,并且需要将所选文件复制到另一个位置。我是 Apple Scripting 的新手,所以可能犯了一些错误。我尝试了使用“复制”而不是“重复”或“别名”而不是“文件”的不同版本,但到目前为止没有任何效果。希望有人能帮我解决这个问题。

这是我目前编写的脚本(我得到一个 AppleEvent 超时):

set DefaultPath to POSIX file "/Users/jan/Library/Mobile Documents/com~apple~CloudDocs/FOLDER/Test"
    set DestFolder to "/Users/jan/Library/Mobile Documents/com~apple~CloudDocs/FOLDER/Destination"
    set theFile to (choose file with prompt "Select file:" default location (DefaultPath))
    tell application "Finder"
        duplicate theFile to folder DestFolder
    end tell

【问题讨论】:

  • 如果你让你的 DestFolder 引用一个 posix 文件,它应该可以工作。正如所写,它是一个字符串,而不是文件引用。
  • 非常感谢,只需稍作改动就可以了。太棒了。

标签: macos automation applescript


【解决方案1】:

问题在于 Finder 不支持 POSIX 路径。

我建议使用相对路径 path to library folder from user domain 和 HFS 路径(冒号分隔)

要满足choose filelocation 参数,请将alias 关键字放在(HFS)路径的前面

set cloudDocs to (path to library folder from user domain as text) & "Mobile Documents:com~apple~CloudDocs:"

set DefaultPath to cloudDocs & "FOLDER:Test:"
set DestFolder to cloudDocs & "FOLDER:Destination:"
set theFile to (choose file with prompt "Select file:" default location (alias DefaultPath))
tell application "Finder"
    duplicate theFile to folder DestFolder
end tell

【讨论】:

  • 你是我的英雄。非常感谢您的快速帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-21
  • 2015-01-30
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多