Applescript, Clipboard, Libraries and Stand-alones

Thomas McGrath III 3mcgrath at comcast.net
Tue May 6 15:06:56 EDT 2008


Mark,

I was having all kinds of problems with the write to and read from  
file method, mostly path issues. Don't forget I have to have this work  
in AS, VB and in RR in order to be of use to me on both Mac and  
Windows platforms.

And, I was not getting RR to read the file correctly  from the hex  
data returned straight from the AS script.

Nothing else in my library writes to the users disk and I wanted to  
keep this consistent if I could.

So I looked into the clipboard info and found that AS and VB will  
convert the raw data into binary on the clipboard. So getting RR to  
just read the binary clipboard instead of the hex data seemed like the  
logical step. However paste was not working in RR correctly for me and  
after a while I thought maybe I was not copying correctly from AS. So,  
I looked up in the scripting additions library for clipboard where it  
does state:

set the clipboard to v : Place data on an application’s clipboard.  
Use inside a ‘tell’ block and activate the application first
set the clipboard to any : the data to place on the clipboard

the clipboard v : Return the contents of an application’s clipboard.  
Use in a ‘tell’ block after activating the application
the clipboard
[as type class] : the type of data desired
→ any : the data

clipboard info v : Return information about the clipboard
clipboard info
[for type class] : restricts to information about only this data type
→ list of list : a list of {data type, size} for each type of data on  
the clipboard

ANYWAY, after playing around all day and getting frustrated I decided  
to go back to my script that just pasted on the clipboard (Finder?)  
and do it different this time from within RR instead. It now works  
consistently without a paste in RR, but rather a  
clipboardData["image"] instead:

Applescript: (This successfully puts the artwork converted to binary  
on the clipboard every time, <name> and <playlist> are replaced.)
try
	tell application "iTunes"
		set myHasArtwork to the artworks of track "<name>" of playlist  
"<playlist>"
		if myHasArtwork is not "" then
			set myTrack to the (data of artwork 1 of track "<name>" of playlist  
"<playlist>") as picture
			set the clipboard to myTrack as picture
			return myTrack
		end if
	end tell
end try

Then in Revolution:
-- set up a correctly sized invisible image to store the data in and  
then use it's ID for my buttons and or other images

put the clipboardData["image"] into tTemp
put tTemp into img "Template"
put the id of img "Template" into theResult
put "Image ID:" && theResult into field "Sample"
     -- Now put the new image into a new sized and locked image or set  
up for the icon of a btn etc.
put image id theResult into image "Album Artwork"

Well, after a long day, this is now working consistently and if I need  
to save the file I can now do it from within RR with a simple path  
instead of having to set up paths in AS and VB and RR.

Thank you for you help and suggestions,

Tom McGrath

On May 6, 2008, at 1:42 PM, Mark Schonewille wrote:

> Tom,
>
> Did you see my last reply regarding your problem concerning PNGs?
>
> I don't know where you got the instruction to activate an  
> application before setting the clipboard, but this seems like  
> nonsense to me. The clipboard usually works at system level. It  
> shouldn't be necessary to do this inside a tell block.
>
> Can't you just have AppleScript return the data to Revolution and  
> use a Rev script to read the picture from the result, like you did  
> earlier?
>
> Best,
>
> Mark



More information about the use-livecode mailing list