Saving Clipboard Contents in a variable

Hi,

So I have a script which copies selected text from any app and uses pbpaste to pass it to a command line app that processes it and returns a result that I then go on to use to create calendar events.

The script works fine, except, I didn’t want the script to have a lasting affect on any pre-existing clipboard contents, so I save the clipboard contents in a variable before doing the copy and then I put it back on the clipboard when my script finishes. However, sometimes, what’s on the clipboard isn’t just plain text and I get this applescript error:

Here’s the code that generates the error:

set theSpare to the clipboard as record

Is there a better way to do this that avoids the error?

Thanks,
Rob

Hi Rob,

Are you saving records in the file?

gl,
kel

So I’m only a dabbler in Applescript and I’ll admit I get a lot of code via copy/paste. The “as record” must’ve been from some web post. I figured it out the other day but hadn’t followed up. Simply removing " as record" solved the problem.

Thanks!
Rob

Yes, because when you save as record you need to read as record. Reading as record won’t work on non-record file. Glad you got it going.

gl,
kel