使用AppleScript选择文件

问题描述 投票:0回答:1

我试图让AppleScript选择文件,但是执行脚本时出现错误。

这里是代码

tell application "System Events"
    set a to "/Users/me/files/"
    set fileName to "myFile.jpg"
    set thePath to POSIX path of a
    tell application "Finder"
        set selection to fileName of thePath
    end tell
    keystroke "c" using command down
end tell

我遇到错误“无法获取“ / Users / me / files /”的POSIX路径]

基本上,我想做的是找到一种选择文件的方式,以便以后可以复制它。但是我想复制实际文件,而不是文件路径。这个想法是创建一个复制文件的服务,以便我可以轻松地将其粘贴到另一个应用程序中。

如果有更好的方法可以做到这一点,请告诉我

macos file select copy applescript
1个回答
0
投票

以下这两行代码会将您的文件复制到剪贴板。这仅适用于单个文件。没有多个项目。

activate
set the clipboard to POSIX file (POSIX path of (choose file))
© www.soinside.com 2019 - 2024. All rights reserved.