Stupid Mac::Glue Tricks: Clipboard Cleaning

| | Comments (0)
I hate that the Mac likes to put styled text on the clipboard and use it everywhere. Like when I am in Safari, I ctrl-click a link and select "Copy Link," and I get styled text of the link text that is hyperlinked. I do not want that. I want the link. So I have to paste it into Safari or BBEdit, then select it and copy it again, so I can paste it into iChat without being retarded.

And I don't care if you like it that way! I don't.

So I figured I'd use this simple AppleScript:

set the clipboard to (the clipboard as string) as string

It seemed to work, except that it still carried some text style information in it. I have no idea why. So I tried the equivalent Perl version:

use Mac::Glue ':all';
my $glue = new Mac::Glue 'Finder';
$glue->set_the_clipboard_to($glue->the_ clipboard(as => 'string'));

That works. Why?

The returned Apple event does not return merely the text, but a record containing text and some default style information. The Mac::Glue version knows you want the text and sucks that part out, but the AppleScript version keeps the style information for you. Once I figured this part out, it was a matter of duplicating that behavior in AppleScript (I could leave it in perl, but the perl version can take a couple of seconds, and I'll be putting this in the Script Menu and calling it regularly to clean my clipboard).

So here's the final version, which first converts the returned clipboard value to a record, then extracts the key containing the text:

set the clipboard to «class ktxt» of ((the clipboard as string) as record)

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on July 11, 2006 10:35 PM.

North Korea Framework was the previous entry in this site.

Climate Change is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.