Copy file content (not path) to clipboard

There are dozens and dozens of ways of getting a file name and path on to the clipboard, but I can not find any way of getting a file itself onto the clipboard.

For example, if you select a file in the Finder then hit Control-C, the file itself shows up on the clipboard and the paste menu reads “Paste Item”. What’s relevant to me, is that, in this form, the file on the clipboard can be pasted, as content, in other applications. If the file is a Movie, for example, I can paste that movie into a TextEdit document.

How can I do this with AppleScript? I would like to be able to put a movie file onto the clipboard, preferably from the Finder, then paste it into a document as content.

Can this only be done with System Events and sending “control-c”?

Thanks,
Conrad

Model: PowerBook G4
Browser: Firefox 1.0.3 (PowerBook)
Operating System: Mac OS X (10.3.9)

I’ve played with this and the only problem is you may end up with a limit on the clipboard’s contents.


set the file_to_read to read ¬
	(choose file with prompt ¬
		"Pick a text file to summarize:")
set theSummary to paragraphs of file_to_read
tell application "Finder"
	set the clipboard to the result as text
end tell


SC

Thank you very much for your reply sitcom! It’s much appreciated. I’m afraid you’ve misunderstood my request however. I can get text on the clipboard fine, but I can not get a movie file onto the clipboard. It is possible to past multimedia content, like a movie, into a TextEdit rich text document. I would like to be able to do just that.

thanks again,
Conrad

Model: PowerBook G4
Browser: Firefox 1.0.3 (PowerBook)
Operating System: Mac OS X (10.3.9)

I’m afraid you’ve misunderstood my request however.

Doh!! :stuck_out_tongue:

OK now you’ve got me intrigued… You say it is possible to get the “content”. Do you mean the movie will show up it the text document and be viewable, sound and all? I can copy and paste the frames of the movie, but not the whole movie. Can you explain what I would see when I look at the finished document if a script processed it correctly?

SC

If you drag a movie into TextEdit it looks like this.

If I understand you correctly, this is what you want…

tell application "Finder"
	activate
	select (alias "Macintosh HD:Users:jed:Desktop:Landscaping:Pool1.jpg")
end tell

tell application "System Events"
	tell application process "Finder"
		keystroke "c" using command down
	end tell
end tell

This places a copy of the file into the clipboard (using gui scripting), which can be pasted using a paste command or other method of extracting pasteboard data. Note that this is using 10.3.9, in which the dictionary for the finder does NOT support the ‘copy’ command. It is listed as a future command though, so users of 10.4 could check to see if the copy command has been implemented in tiger, which may make this a lot easier and more reliable.

j

Thank you jobu, guardian34, and sitcom for you replies! I really appreciate your taking the time to help me out. I was able to implement this process just as you’ve outlined it. I’m wondering why isn’t there a coercion or “as datatype” reference to do this? For example, anthoer way to do the same thing is to open the media file (image or movie or what have you) in QuickTime Player and hit copy (command-c) there. However, opening the media in QT Player via AppleScript, then putting that video as a variable on the clipboard doesn’t work either. It seems that the only way to do this is through the emulation of the key-stroke, which really surprises me. It seems that there is a way for the OS to add elements to the clipboard in a data-type sensitive way. I’m surprised that Applescript doesn’t have any hooks into this. I had expected that the commad
set the clipboard to variable as alias
would put the content on to the clipboard in a data type agnostic way. I would also expect that Applescript would handle the alias in the richest way possible, letting the system sort out data type compatibility. But no luck.

Thanks you guys. I really appreciate the help. If you have any other ideas, please post them.

best,
Conrad

Try this thread:
http://bbs.applescript.net/viewtopic.php?id=11010
If you are planning on grabbing frames from a movie file then iMaginePhoto.
iMagine Photo, the best tool for processing image files using AppleScript. http://www.yvs.eu.com

Brandon Carpenter
Book Reviews & Links @ Macscripter.net

Model: iMac DV (summer 2001)
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

Thanks Brandon! That helps a lot. It’s interesting - if you use this method to insert an attachment into a richtext document, then put the content onto the clipboard, only a reference to the file ends up on the clipboard, not the content. The richtext doc has the content, but trying to put the content on the clipboard only gives me the file ref.

Thanks again,
Conrad