Three Clipboard to Plain Text options for the Mac

On occasion I find that I need to take text from one Mac application and convert it into plain text for use in another application.  I’ve been copying the original content to the Mac’s clipboard, pasting it into a text editor application (to remove the formatting), copying that text and then pasting it into the application I want it in.  This is a laborious process and one which I was sure could be improved upon.

To me this seemed to simply be a workflow issue, so the obvious approach was to look at using some sort of combination of things like Automator, AppleScript or even some shell scripting.  Very quickly I came up with a line of AppleScript that would in effect carry out the task I had been doing without needing to resort to using a text editor, but simply by modifying the clipboard content directly.

set the clipboard to (get the clipboard as text)

This could then be pasted directly into the application.  In fact by adding an additional line of script I can even have the script paste the text for me automatically.  This is especially useful as using Automator you can create a workflow with this AppleScript, save it as a service (with ‘no input’, being ‘available in any application’ and not being set to replace selected text), and then set that service to be called by a specific key press (e.g. ALT+CMD+V).

set the clipboard to (get the clipboard as text)
tell application "System Events" to keystroke "v" using {command down}

The unfortunate thing about this method is that it replaces the rich clipboard content with the plain clipboard content so if you want to get the rich content again (which I do on occasion), you have to go back and copy it to the clipboard again.  So this is useful, but I thought could be better.

I looked at various ways of trying to store the clipboard content in a variable or file, but it seems that the clipboard is a multi-format storage area and trying to store that using AppleScript or a shell script seemed to be a little beyond the script capabilities.  So at that point there were two options available - find something that could manage the clipboard or find another way of outputting a plain version of the clipboard content.

‘The Apple Blog’ had an article on ten clipboard managers for the Mac so this was my starting point.  I thought that one of these might have the option to be scriptable.  What I found instead was ClipMenu which actually has a built in feature to output as plain text directly from the clipboard.  What it does is take the rich clipboard content and then copy a plain version of that to the clipboard.  So now both a plain version and a rich version are available.

So for the most part this is a really good solution - particularly since ClipMenu is free software.

However I get frustrated with loose ends and the developer part of my brain is a little distracted by the fact that the plain text is being held by the clipboard manager in addition to the rich text.  That’s a duplication of data and that’s not ideal.  I fully realise that this is a trivial point, but perhaps I have some sort of developer OCD that means these things just irk me a little, and I do still have ClipMenu installed because it is useful.

So the other option I had left to explore was to look at getting the data out of the clipboard in some non-destructive fashion.  Whilst somewhat crude and not particularly quick we can take the plain content of the clipboard and type it out through key presses with a single line of script.  Again by putting this script into Automator and saving as a service we can have another option for outputting the content of the clipboard as plain text tied into a keyboard shortcut.

tell application "System Events" to keystroke (get the clipboard as text)

So there you have three options.

  1. You could use a clipboard manager like ClipMenu with a built in plain text function.  This will give give some duplication of clipboard content, but also the option of having a clipboard history and several other filter features (e.g. convert to uppercase).
  2. You could use an AppleScript and Automator to create a service to replace the content of the clipboard with plain text version and then paste that into your application.
  3. You could use an AppleScript and Automator to create a service to type out a plain text version of the clipboard content directly into your application.

They’re not mutually exclusive and I now have all three in place, so for those of you who don’t like to limit your choices you don’t have to.

Author: Stephen Millard
Tags: | applescript | automator |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read