− 065 −
Stupid Clipboard Tricks
January 31st, 2014
Clipboards and Pasteboards are the topic of the week, as Gabe breaks down the tools and utilities he uses to get through the day on his Mac.
How did you just do that?
After reminiscing about how confusing and surprising other people’s Portal runs can be, Gabe tries to figure out why Erik isn’t using a clipboard manager.
- Rich Text to plain text/Markdown conversion
- Converting text case
- Appending text
- Stripping characters
- Encoding Strings
Many people treat the clipboard as a temporary way station between apps. While that’s true, it’s also an opportunity to transform and manipulate the information before it gets to its final destination.
Plain text is awesome, but many apps support RTF formatting that can be a nuisance when jumping to another app like your email client. While some applications support the “paste and match style” function, that’s not a universal option. Rather than relying on some developer’s whim, try stripping out the formatting when the text is on the clipboard.
The clipboard is another good opportunity for converting and encoding text. Whether it be converting lower case to title case or URL encoding a string, why bother using a totally separate application when it’s already on your clipboard?
Sync and Online Services
Sync or Share
I refer to these services as clipboard syncing services which is technically incorrect. I use them as a way to share clips between devices. Some use them to share clips with other people. Using any of these services to make clippings available between devices requires a conscious effort to put the material on their host.
If what you want is true clipboard syncing then there are a few methods. CloudClip is what I would recommend. It doesn’t have a web interface but it does sync your clipboards over the Internet using iCloud. There are also utilities that use Bluetooth like Scribe, but those require your devices to be near each other and connected by Bluetooth. There’s also Command-C which works over WiFi.
I still prefer Evernote because it’s available everywhere, including the web and Windows. I also rarely wish that my clipboards were “automatically” syncing. I don’t want sensitive data flying around unnecessarily.
Of the three of these web-based clipboard services, Gabe prefers Evernote for its ubiquity. Previously, he was a CloudApp user. All three can handle images and formatted text. Droplr has the best support for code snippets. They all provide options for sharing links to clippings and are private by default. You can’t really go wrong with any one of these services.
The CloudApp Mac app is a good option if just want a web-syncing clipboard tool. The Mac app is easy to use and provides a history view of the items you have uploaded.
Why Do It?
I’d suggest thinking carefully about what you are trying to accomplish with clipboard syncing and sharing services. Most of my needs are simply to get bits of information from my Mac to an iOS device or vice versa. These are usually one off situations. I have never encountered a problem that required my entire OS X and iOS clipboards to be perfectly in sync. Most of the time, I really just need a bit of text on my phone that I have on my Mac. There are numerous ways to do this today.
Most text editors sync through Dropbox before you can even open your other device. Before there were good reliable ways, I used Pastebot. However Pastebot hasn’t been tocuhed in a very long time and is downright horrible on an iPad. I’d also suggest that iMessage is a good basic solution for getting information between Apple devices.
- Chrome Plain Text Passwords
- Alfred Clipboard History and Snippets
- Brett Terpstra’s TextExpander Tools
iClip is a very good and highly visual clipboard manager. It’s not as sophisticated as some of the tools Erik and Gabe dive into, but it may be the right fit if you just want an easy to use clipboard history browser on your Mac.
CopyLess is the one Gabe prefers, because of his penchant for removing all text styling on the clipboard. This area is so well served that it may just take one feature to win you over. CopyLess has good keyboard shortcuts and does a good job of preserving information like the source app in the history view.
The pbcopy and pbpaste Commands
Mac OS X provides the built in Darwin functions pbcopy and pbpaste. This is a simple way to write scripts that work with the system clipboard. I’ve used it in many Python scripts and Keyboard Maestro macros without a problem.
If you are already an Alfred user, then you already have a pretty good clipboard history app. Just turn it on in the Alfred preferences and configure a shortcut. The history can go back as far as 3 months but it’s user configurable. You can even exclude some application like 1Password from the history to avoid holding on to sensitive information too long.
Local vs. Web History
Since applications like Keyboard Maestro and Alfred only exist on my Mac and do not sync information over the Internet, I don’t have any concerns about sensitive information being recorded in the history. I use FileVault on my Mac, so in theory someone would need to know my master password to view the history. However, there are plenty of tools that sync information through the Internet and I would think twice about allowing them to grab my passwords.
Keyboard Maestro is a macro execution system for the Mac. Macros are simple to assemble, using a wide range of flexible pre-configiured actions. Many of the macros that Gabe describes use the standard actions available without any programming knowledge required.
One Tool to Rule Them All
There are so many options for powerful and customizable workflow tools on the Mac that it can get a little messy. I’ve assigned each of my primary tool-chains to a different domain. All snippet expansion is done with TextExpander, unless there’s something it just can not easily do. All keyboard shortcut actions are handled by Keyboard Maestro. All launcher and search functions are handled by Alfred.
Clipboard actions was the first domain that it was difficult to restrain myself because TextExpander, Alfred and Keyboard Maestro each do something the other does not. I’ve settled on using Alfred for the basic clipboard history stuff and Keyboard Maestro for everything else.
The Keyboard Maestro clipboard history viewer can be as simple as a list of your most recent additions. You can also create and manage any number of custom clipboards separate from the system clipboard. The items in the clipboards are static and live on after reboots.
Down the Vim rabbit hole
Vim also has the ability to use multiple clipboards of a sort, and they are called registers. If you have used Vim at all, you may already know a register as the thing you yank (copy) or delete (cut) into. This particular register is known as “unnamed,” and there are nine types of registers in all. Registers are identified first with the
"character, and the unnamed register is really just named
"". I’d like to highlight a couple of nice things about these registers.
As you yank (
y) or delete (
x) you move your selection into
""and into the numbered register
0with a yank or register
1for a delete or change. I often delete a few items before realized that I still needed some of the text, but the nice thing is all may not be lost, because each time you delete or change, the item in
1is rolled to
3, etc. Gone but not forgotten…well, except for item number nine. It actually is forgotten, so this is only good for a quick fix. If you know you will need some text again, put it into a named register. Note that the
0is always the last yanked item, and it never rolls anywhere. That is because you don’t delete text when you yank it, so it isn’t lost the same way deleted text can be.
When the goal is text re-use, you can specify one of 26 single-letter named registers. A lower case number fills the register from scratch, but a capital letter appends to what’s already in the register. I know, Vim is awesome. An example command to illustrate this is
"ryy, which yanks the entire line into the
rregister. To get it back out of there, you could type
"rpwhich puts (pastes) the yanked line into place after the cursor.
It’s easy to lose track of the state of your registers, so remember that you can type the command
:regto print out all of your defined registers. I could go on, but I hear the conductor playing me off the stage.
Keyboard Maestro also provides a way to share the full contents of a clipboard instance between Macs on the same network. Jump into the preferences an enable the webserver on the Macs.
As an exmple of how simple it is to use Keyboard Maestro to do complex clipboard manipulations, Gabe describes a macro to paste the clipboard text through typing. That macro can be as simple as a single pre-made action. With a just a couple of tweaks, you can create a macro that responds appropriately to based on the content current on the clipboard. If it’s text, it gets typed out, if not, it gets pasted as normal.
Gabe also mentions a “plain text clipboard” in Keyboard Maestro. This macro copies text to a named clipboard and automatically removes all styling information.
Keyboard Maestro also provides actions for doing very sophisticated things with text. For example, URL encoding a string by converting things like spaces, brackets and other “un-safe” characters with a single macro action.
TextExpander is typically used to expand snippets but it also includes functions for working with the clipboard contents. You can also trigger a shell script or AppleScript to be executed during snippet expansion. That’s an easy way to grab the clipboard and start ripping it apart.
Unlike Keyboard Maestro, TextExpander will only operate on text after it has been placed on the clipboard rather than converting selected text.
One place where TextExpander wins, is with the cursor position token. After expanding a snippet, the cursor can be repositioned within the string.
The Clipboard Conduit
It’s easy to think of the clipboard as just a temporary holding place between apps or for a short period of time. When I started to think of it as an entry point for scripts and macros, it transformed (pun intended) the way I worked. If I can get it on my clipboard, I can do almost anything with it.
Until next week
Well, that’s it for this week. If you have anything that you’d like to add to or correct in the show notes you can find me on Twitter @potatowire or feel free to send an email to me at potatowire dot com.