简体   繁体   English

使用 applescript 将多个 POSIX 文件复制到剪贴板

[英]Copy multiple POSIX files to clipboard with applescript

I'm trying to copy multiple files to the clipboard in macos like this:我正在尝试将多个文件复制到 macOS 中的剪贴板,如下所示:

./file2clip.applescript /User/Cool/Dekstop/test.txt /User/Cool/Dekstop/myfolder

I already can do this with only one file:我已经可以只用一个文件来做到这一点:

#!/usr/bin/osascript
on run args
    set the clipboard to POSIX file (first item of args)
end

But it only works on one file...但它只适用于一个文件......

I have tried this我试过这个

on run args
    set the clipboard to POSIX files args
end

But It didn't work.但它没有用。

And also this还有这个

on run args
    set pathList to {}
    repeat with arg in args
        set end of pathList to POSIX file arg
    end repeat
    set the clipboard to pathList
end

But this also didn't work但这也没有用

Adding all the POSIX files to a string also doesn't work because the clipboard will have only text inside it so I can't paste all the files with ctrl + v , I could only paste their names.将所有 POSIX 文件添加到字符串中也不起作用,因为剪贴板中只有文本,所以我无法使用ctrl + v粘贴所有文件,我只能粘贴它们的名称。 Not what I want to achieve.不是我想要达到的。

property files: ""

on run args
    repeat with f in args
        set files to files & POSIX file f & "\n"
    end repeat
    set the clipboard to files
end

Any ideas?有任何想法吗?

In your original snippets, setting the clipboard to the first argument item works because it is text.在您的原始片段中,将剪贴板设置为第一个参数项是有效的,因为它是文本。 Setting the clipboard to a list appears to fail because it is a list - the data is there, it just doesn't work the same as text ( clipboard info can be used to get information about items on the clipboard).将剪贴板设置为列表似乎失败,因为它是一个列表- 数据在那里,它与文本的工作方式不同( clipboard info可用于获取有关剪贴板上项目的信息)。

From the command line, arguments (quoted and/or escaped as needed) should already be passed on to the script as a list of POSIX paths, but coercions and/or manipulations such as tilde expansion can also be performed as needed.从命令行中,arguments(根据需要引用和/或转义)应该已经作为 POSIX 路径列表传递给脚本,但也可以根据需要执行强制和/或操作,例如波浪号扩展。 The individual items can be placed onto the clipboard however you want using regular text operations - for example, to separate the arguments with returns, you can just do something like:可以使用常规文本操作将各个项目放置到剪贴板上,但是您希望使用常规文本操作 - 例如,要将 arguments 与返回分开,您可以执行以下操作:

on run args
    set pathString to ""
    repeat with arg in args
        set pathString to pathString & arg & return
    end repeat
    set the clipboard to pathString
end run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM