Saturday, February 22, 2020

CopyQ for the impatient - Introduction

CopyQ is a really handy clipboard manager. As its name suggests, it enables you to easily return to previous items in your clipboard, but as you will see later, it offers much, much more. Thanks to its scripting capabilities, it is also a handy automation tool. I'm a big fan of CopyQ and I think it deserves more promotion, so I decided to create this, hopefully useful wrap-up.

Why to use it, and not something else?


On AlternativeTo, CopyQ holds the 2nd position with 162 likes at the time of writing. The 1st place is occupied by Ditto with 304 likes, but Ditto has one big disadvantage: it is only for Windows. For me, CopyQ is also much better when it comes to options of running custom commands (scripting). Both apps are free and open source.

When talking about Windows, since a recent Windows 10 build, you might use their built-in clipboard manager as well (just try to press Win+V if you own one). But even without trying out, I'm sure it will be pretty much behind CopyQ & co. when talking about productivity-boosting features for advanced users - just read on!

Features


Firstly, to make a basic idea of the app, here is a screenshot of its main window:

An example of CopyQ's main window, illustrating some basic terms.


Here are the main distinguishing traits of CopyQ:
  • Runs and offers the same interface on Linux, Mac and Windows.1
  • Supports images as well as formatted text.
  • You can search the clipboard history easily (supports regular expressions).
  • It has a simple built-in editor of clipboard items.
  • You can control what gets into the clipboard history. And of course, the history is persisted among computer restarts.
  • If you want, you can control it from command line as well.
  • Nearly endless possibilities of customization, including running custom commands (see Commands).
  • A superb documentation (see Documentation).
And to mention some advanced "enterprise" features:
The only nice-to-have feature which is missing, is probably an automated synchronization of commands across multiple machines (e. g. in a company)...

Basic setup


So now that we know what CopyQ can do, how to make it run on our machine? We start by downloading an installer or a portable archive - simply follow the installation instructions.

Once the CopyQ is installed and running, we set a global keyboard shortcut for showing the CopyQ's main window. Firstly, we need to open the Configuration dialog from the system tray:


Secondly, we set the shortcut in the opened dialog:


Here we inspired from Ditto's default shortcut, which is Ctrl+` - i. e. hold down Ctrl and press the back-quote (tilde = ~) key.2

In the same dialog, we can choose whether we want immediate pasting after selecting a clipboard item from history, or not:



Add a tab for your favorite snippets


Next, we might want to add a tab for keeping our favorite code snippets (as seen on the very first picture above), or whatever we intend to use it for. This is as easy as pressing Ctrl+T in the main window:



Done!


Now we can just enjoy the CopyQ, let it maintain the clipboard in the background and use its main window and/or shortcuts whenever we need to return to a previous clipboard item, for example. The GUI and default shortcuts are pretty intuitive, so luckily there's only little to learn for the basic usage.

Documentation


CopyQ has a pretty good documentation and this post is definitely not meant to be its replacement. Beware though that there are some little gotchas:

  • The project's home page on Github contains some overlapping information (e. g. installation steps). And it is only here where you can see a quick overview of app's features.
  • If you by coincidence get to a project's wiki page like Basic Usage, run away - it got deprecated and replaced by the newer documentation.

Commands


Attention: It gets a little bit more technical in here!

Pressing F6 in the CopyQ's main window takes you to the management of commands:

An example of the Commands window. It shows the source code of one of the many built-in commands (selected & inserted via the "Add" button). Properties of the command are set in the "Advanced" tab.


While working with commands in CopyQ is great and thoroughly documented, I miss a quick overview of some concepts for newbies. So here is my little attempt to fix that (You might still want to read the official glossary page first.):

  • Commands are either built-in, or user defined. Every command is actually a readable script (with some necessary metadata - options). For the impatient: see this paragraph for various forms of the command scripts.3
  • Every command may be run in different contexts depending on what checkboxes get selected in its "Type of Action" options section. That is:
    • automatic (when there's a new clipboard item)
    • in menu (to run it over selected item(s); a shortcut may be assigned)
    • global (to run it at anytime when needed; a global shortcut may be assigned)
    • display (changes how items look like in the main window)
    • script (changes the default set of available functions, so a more precise name would be an "extension script")
  • If you don't see a built-in command, you need to explicitly add it to available commands via the Commands window (F6). Or, you can achieve the same effect by assigning a shortcut to the command in the Configuration dialog (Ctrl+P).
  • The Action Dialog dialog (F5) lets you run an ad-hoc command script instead of an existing named command. You have to explicitly select a "Standard input" for passing the content of selected item(s) to the script.
    Here's an example, showing a rather improbable scenario of converting a URL address to uppercase:

All-in-all, with CopyQ commands you can do lots of interesting stuff and there are many ways of how to create and use them. There is even a library of commands from the author(s) in a dedicated Github project called copyq-commands. Maybe in another post we will take a closer look at this!

Follow-up article: CopyQ - The most useful commands.

1 Ordered alphabetically.

2 Beware though that a keystroke which includes a key that maps to different characters based on the current keyboard layout (like Ctrl+`) doesn't have to work under all circumstances. See issue 1323 for more details.

3 As you may have guessed, the "copyq:" scripts are written in ECMAScript and you can call built-in CopyQ functions from them. So if you are familiar with JavaScript, you'll be like at home here.