Reputation: 425
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!
Upvotes: 0
Views: 398
Reputation: 1
What works best for me is to tell the Finder to copy the file to the clipboard. The finder takes care of all the details, different file classes etc.
osascript -e 'tell app "Finder" to set the clipboard to ( POSIX file "/Users/someuser/somefile.zip" )'
You need to provide an absolute path and e.g. avoid "~" (home directory).
I tested this with pasting to Finder windows, Apple Mail and Microsoft Word.
Upvotes: 0
Reputation: 1878
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
Upvotes: 2