It is currently Sun May 19, 2013 9:53 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Copy file to clipboard
PostPosted: Sun Jun 10, 2012 1:37 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 640
Location: Cologne, Germany
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 viewtopic.php?f=19&t=40684 to accomplish this.

Code:
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$)


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

_________________
Regards,
JamiroKwai

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
 
 Post subject: Re: Copy file to clipboard
PostPosted: Sun Jun 10, 2012 8:52 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 849
Location: Seattle, USA
Code:
If CreateImage(0, 26, 20)
    StartDrawing(ImageOutput(0))
      Box(0, 0, 26, 20, RGB(255, 255, 255))
      Circle(13, 10, 5, RGB(255, 0, 0))
    StopDrawing()
    SetClipboardImage(0)
  EndIf


This example from the Help folder works ok for me. I was able to paste the clipboard into Preview and into another drawing program. I'm thinking the problem might be with systems newer than Snow Leopard.

Maybe someone else can try it and say if it is working for them.

_________________
MacBook Pro/Retina, OSX 10.8.3 Mountain Lion, PB-5.11x64


Top
 Profile  
 
 Post subject: Re: Copy file to clipboard
PostPosted: Sun Jun 10, 2012 10:18 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 640
Location: Cologne, Germany
WilliamL wrote:
This example from the Help folder works ok for me. I was able to paste the clipboard into Preview and into another drawing program. I'm thinking the problem might be with systems newer than Snow Leopard.


Didn't think of this before. On Lion, the example will definitely NOT work.

_________________
Regards,
JamiroKwai

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye