将文件复制到Finder剪贴板使用Bash/Applescript

huangapple go评论58阅读模式
英文:

Copy File To Finder Clipboard Using Bash/Applescript

问题

使用Finder时,您可以选择一个文件,然后按Command+C将文件本身复制到剪贴板,这样您可以轻松粘贴到另一个目录,甚至粘贴到电子邮件、即时消息或其他浏览器输入中。这对日常任务非常有用,特别是对于图像和屏幕录制。

我正在编写脚本以提高生产力,想知道是否有办法使用bash或AppleScript以这种方式将文件复制到Finder剪贴板?

我似乎无法在网上找到它。大多数命令行工具只复制文件名或文件内容(如果是文本)。

有人知道如何解决这个问题吗?

感谢您的帮助!

英文:

When using Finder, you can select a file and Command+C to copy the file itself to the clipboard, allowing you to easily paste it into another directory, or even into an email, messenger, or other browser input. This is very useful for daily tasks, especially for images and screen recordings.

I'm writing scripts for improved productivity and wonder if there is a way to copy a file to the Finder clipboard in this way using bash or AppleScript?

I can't seem to find it anywhere on the web. Most command-line tools only copy the file name or file contents (if it is text).

Does anyone know of a solution to do this?

Thanks for your help!

答案1

得分: 2

在AppleScript中,您可以使用**「类别furl」引用**将文件/文件夹复制到剪贴板。

set the clipboard to "/Users/123/Desktop/MacScripter .webloc" as «class furl»

将它们放在剪贴板中,您可以将这些引用粘贴到可以接受它们的应用程序窗口中。

注意:要测试这一点,请指示您的Mac上某个现有文件的Posix路径。在我的测试中,我可以将上述文件粘贴到Finder.app窗口或Mail.app的新消息窗口中。

英文:

In AppleScript, you can copy files/folders to the clipboard using the «class furl» references.

set the clipboard to "/Users/123/Desktop/MacScripter .webloc" as «class furl»

Having them in the clipboard, you can paste this references into the application windows which can accept them.

Note: to test this, indicate Posix path of some existing file on your Mac. In my testings, I can paste the file above into any Finder.app window or New Message Window of Mail.app

huangapple
  • 本文由 发表于 2023年6月12日 01:24:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76451661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定