Copy file to clipboard
Posted: Sun Jun 10, 2012 1:37 pm
Hi board,
I found out how to copy (at least) JPGs to the clipboard on Mac OS X. This should work for every type of file...
The SetClipboardImage()-command will copy the image to Clipboard, but will use some kind of TIF-Format, which e.g. Preview.app cannot use.
So I used the AppleScript-Wrapper by wilbert from http://www.purebasic.fr/english/viewtop ... 19&t=40684 to accomplish this.
You have to copy your image to /tmp/file.jpg before calling the script. You can remove /tmp/file.jpg safely after copying.
It should work with every file type, e.g. MP3, WAV, PNG and such.
Edit: William asked, what is wrong with the PureBasic-way. This: If I set some image (format does not matter) to the Clipboard using SetClipboardimage, the resulting TIF can be viewed using "Show Clipboard" in Finder-Menu (if it is called this way). But neither Preview.app nor Finder can paste the Clipboard to a new image or image-file. Using the above way, you copy an object to Clipboard, with can be used with Preview.app
I found out how to copy (at least) JPGs to the clipboard on Mac OS X. This should work for every type of file...
The SetClipboardImage()-command will copy the image to Clipboard, but will use some kind of TIF-Format, which e.g. Preview.app cannot use.
So I used the AppleScript-Wrapper by wilbert from http://www.purebasic.fr/english/viewtop ... 19&t=40684 to accomplish this.
Code: Select all
script$ = "tell application " + Chr(34) + "Finder" + Chr(34) + " to set the clipboard to (POSIX file " + Chr(34) + "/tmp/file.jpg" + Chr(34) + ")"
COCOA_AppleScript(script$)It should work with every file type, e.g. MP3, WAV, PNG and such.
Edit: William asked, what is wrong with the PureBasic-way. This: If I set some image (format does not matter) to the Clipboard using SetClipboardimage, the resulting TIF can be viewed using "Show Clipboard" in Finder-Menu (if it is called this way). But neither Preview.app nor Finder can paste the Clipboard to a new image or image-file. Using the above way, you copy an object to Clipboard, with can be used with Preview.app