Convert text in clipboard

I looked into this but to no avail. Is there any way to take copied text that is in the clipboard, then convert that text to unicode text and resave it to the clipboard. This way, any rich text formatting would have been removed upon paste.

I am not worried about the “copy” aspect. I will use QuicKeys to assign a keyboard shortcut such as “Cmd-Opt-Ctrl-C” which will run the script.

Any ideas or paths upon where to look?

Thanks,
Jeff

Hi Jeff,

as the clipboard holds several types a conversion is not needed


set theUnicodeText to Unicode text of (get the clipboard as record)

To save to the clipboard:

set the clipboard to (the clipboard as unicode text)

Thank you for the replies. This is what I asked for and it works great. However, I suppose I thought this would fix the issue I am having. I am trying to convert speech marks, or smart quotes, into inch marks. I thought changing to unicode would do this, but they are still retained.

Not sure if this displays based on your text encoding, but I want the quotes to appear as the second line below”so they appear as inch marks.

“Some Text”
“Some Text”

try this:

input-valtxt

set valdelms to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\""
set the valtxt to every text item of valtxt
set AppleScript's text item delimiters to ""
set valtxt to the valtxt as string
set AppleScript's text item delimiters to valdelms
return valtxt

On the 4th line you can put an inch mark inside the empty “” quotes. To replace the quotes rather than delete (replace with nothing).

Greetings, folks!

Sorry to dig up a year-old issue, but I’m stumped . . .

I am not having any luck with this same issue. Lucinda Grande text gets copied onto the clipboard, a Ruby script edits the text and puts it back onto the clipboard . . . where it somehow has become Helvetica. I have done endless AppleScript variations of working with the clipboard record (though I’d use Ruby, too) and cannot figure out how to strip out any style formatting.

Stefan’s wisdom at http://macscripter.net/viewtopic.php?id=28741 was (as always!) very helpful, but didn’t get me any closer to a solution.

The following doesn’t work; it still returns styled text:

set theUnicodeText to Unicode text of (get the clipboard as record)
set the clipboard to theUnicodeText
return the clipboard as record -- returns styled text with Helvetica as the font

Another failed attempt (of many):

--> In TextEdit I copy: "this is a test a", then I process it in a Ruby script to change the text case, the result is: "This Is a Test A"
set theClass to «class TEST»
set theClip to (Unicode text of (the clipboard as record))
set the clipboard to {class:theClass, data:theClip, scrap styles:«data styl0000»}
set the clipboard to data of «class TEST» of (the clipboard as record)
-- return the clipboard
--> "This Is a Test A"
return (the clipboard as record) -- even after all the stripping of scrap styles we get:
--> {Unicode text:"This Is a Test A", string:"This Is a Test A", scrap styles:«data styl01000000000010000E00030000000C00000000000000», «class utf8»:"This Is a Test A", «class ut16»:"This Is a Test A"}

I could offer lots more failed attempts, but don’t want to waste bandwidth!

Thoughts?

Thank you!

Richard Fairbanks