1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
|
.. _command-examples:
Command Examples
================
Here are some useful commands for creating custom menu items, global
shortcuts and automatically process new clipboard content in CopyQ.
If you want to use any of the commands below, copy it to clipboard and
paste it to the command list in Command dialog (opened with F6
shortcut). For detailed info see :ref:`faq-share-commands`.
All these and more commands are available at
`CopyQ command repository <https://github.com/hluk/copyq-commands>`__.
Join Selected Items
~~~~~~~~~~~~~~~~~~~
Creates new item containing concatenated text of selected items.
.. code-block:: ini
[Command]
Name=Join Selected Items
Command=copyq add -- %1
InMenu=true
Icon=\xf066
Shortcut=Space
Paste Current Date and Time
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copies current date/time text to clipboard and pastes to current window
on global shortcut Win+Alt+T.
.. code-block:: ini
[Command]
Command="
copyq:
var time = dateString('yyyy-MM-dd hh:mm:ss')
copy('Current date/time is ' + time)
paste()"
GlobalShortcut=meta+alt+t
Icon=\xf017
Name=Paste Current Time
Play Sound when Copying to Clipboard
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Following command will play an audio file whenever something is copied
clipboard.
On Windows:
.. code-block:: ini
[Command]
Name=Play Sound on Copy
Command="
powershell:
(New-Object Media.SoundPlayer \"C:\\Users\\copy.wav\").PlaySync()"
Automatic=true
Icon=\xf028
On Linux (requires VLC multimedia player):
.. code-block:: ini
[Command]
Name=Play Sound on Copy
Command="
bash:
cvlc --play-and-exit ~/audio/example.mp3"
Automatic=true
Icon=\xf028
Edit and Paste
~~~~~~~~~~~~~~
Following command allows to edit current clipboard text before pasting
it. If the editing is canceled the text won't be pasted.
.. code-block:: ini
[Command]
Command="
copyq:
var text = dialog('paste', str(clipboard()))
if (text) {
copy(text)
copySelection(text)
paste()
}"
GlobalShortcut=ctrl+shift+v
Icon=\xf0ea
Name=Edit and Paste
Remove Background and Text Colors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Removes background and text colors from rich text (e.g. text copied from
web pages).
Command can be both automatically applied on text copied to clipboard
and invoked from menu (or using custom shortcut).
.. code-block:: ini
[Command]
Automatic=true
Command="
copyq:
var html = str(input())
html = html.replace(/color\\s*:/g, 'xxx:')
setData('text/html', html)"
Icon=\xf042
InMenu=true
Input=text/html
Name=Remove Background and Text Colors
Linkify
~~~~~~~
Stores an item with interactive link from plain text URL copied to clipboard.
.. code-block:: ini
[Command]
Automatic=true
Command="
copyq:
const link = str(input());
const href = `<a href=\"${link}\">${link}</a>`;
setData('text/html', href);"
Icon=\xf127
Input=text/plain
Match=^(https?|ftps?|file|mailto)://
Name=Linkify
Highlight Text
~~~~~~~~~~~~~~
Highlight all occurrences of a text (change ``x = "text"`` to match
something else than ``text``).
.. code-block:: ini
[Command]
Name=Highlight Text
Command="
copyq:
x = 'text'
style = 'background: yellow; text-decoration: underline'
text = str(input())
x = x.toLowerCase()
lowertext = text.toLowerCase()
html = ''
a = 0
esc = function(a, b) {
return escapeHTML( text.substr(a, b - a) )
}
while (1) {
b = lowertext.indexOf(x, a)
if (b != -1) {
html += esc(a, b) + '<span>' + esc(b, b + x.length) + '</span>'
} else {
html += esc(a, text.length)
break
}
a = b + x.length;
}
tab( selectedtab() )
write(
index(),
'text/plain', text,
'text/html',
'<html><head><style>span{'
+ style +
'}</style></head><body>'
+ html +
'</body></html>'
)"
Input=text/plain
Wait=true
InMenu=true
Render HTML
~~~~~~~~~~~
Render HTML code.
.. code-block:: ini
[Command]
Name=Render HTML
Match=^\\s*<(!|html)
Command="
copyq:
tab(selectedtab())
write(index() + 1, 'text/html', input())"
Input=text/plain
InMenu=true
Translate to English
~~~~~~~~~~~~~~~~~~~~
Pass to text to `Google Translate <https://translate.google.com/>`__.
.. code-block:: ini
[Command]
Name=Translate to English
Command="
copyq:
text = str(input())
url = \"https://translate.google.com/#auto/en/???\"
x = url.replace(\"???\", encodeURIComponent(text))
html = '<html><head><meta http-equiv=\"refresh\" content=\"0;url=' + x + '\" /></head></html>'
tab(selectedtab())
write(index() + 1, \"text/html\", html)"
Input=text/plain
InMenu=true
Paste and Forget
~~~~~~~~~~~~~~~~
Paste selected items and clear clipboard.
.. code-block:: ini
[Command]
Name=Paste and Forget
Command="
copyq:
tab(selectedtab())
items = selecteditems()
if (items.length > 1) {
text = ''
for (i in items)
text += read(items[i]);
copy(text)
} else {
select(items[0])
}
hide()
paste()
copy('')"
InMenu=true
Icon=\xf0ea
Shortcut=Ctrl+Return
Render Math Equations
~~~~~~~~~~~~~~~~~~~~~
Render math equations using `MathJax <http://www.mathjax.org/>`__ (e.g.
``$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$$``).
.. code-block:: ini
[Command]
Name=Render Math Equations
Command="
copyq:
text = str(input())
js = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
html = '<html><head><script type=\"text/javascript\" src=\"' + js + '\"></script></head><body>' + escapeHTML(text) + '</body></html>';
tab(selectedtab())
write(index() + 1, 'text/html', html)"
Input=text/plain
InMenu=true
Icon=\xf12b
Move Images to Other Tab
~~~~~~~~~~~~~~~~~~~~~~~~
With this command active, images won't be saved in the first tab. This
can make application a bit more snappier since big image data won't need
to be loaded when main window is displayed or clipboard is stored for
the first time.
.. code-block:: ini
[Command]
Name=Move Images to Other Tab
Input=image/png
Automatic=true
Remove=true
Icon=\xf03e
Tab=&Images
Copy Clipboard to Window Tabs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Following command automatically adds new clipboard to tab with same name
as title of the window where copy operation was performed.
.. code-block:: ini
[Command]
Name=Window Tabs
Command="copyq:
item = unpack(input())
window_title = item[\"application/x-copyq-owner-window-title\"]
if (window_title) {
// Remove the part of window title before dash
// (it's usually document name or URL).
tabname = str(window_title).replace(/.* (-|\x2013) /, \"\")
tab(\"Windows/\" + tabname)
write(\"application/x-copyq-item\", input())
}
"
Input=application/x-copyq-item
Automatic=true
Icon=\xf009
Quickly Show Current Clipboard Content
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quickly pop up notification with text in clipboard using ``Win+Alt+C``
system shortcut.
.. code-block:: ini
[Command]
Name=Show clipboard
Command="
copyq:
seconds = 2;
popup(\"\", clipboard(), seconds * 1000)"
GlobalShortcut=Meta+Alt+C
Replace All Occurrences in Selected Text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: ini
[Command]
Command="
copyq:
copy();
const text = str(clipboard());
if (text) {
const r1 = 'Text';
const r2 = 'Replace with';
const reply = dialog(r1, '', r2, '');
if (reply) {
copy(text.replace(new RegExp(reply[r1], 'g'), reply[r2]));
paste();
}
}"
GlobalShortcut=meta+alt+r
Icon=
IsGlobalShortcut=true
Name=Replace in Selection
Copy Nth Item
~~~~~~~~~~~~~
Copy item in row depending on which shortcut was pressed. E.g. Ctrl+2
for item in row "2".
.. code-block:: ini
[Command]
Name=Copy Nth Item
Command="
copyq:
var shortcut = str(data(\"application/x-copyq-shortcut\"));
var row = shortcut ? shortcut.replace(/^\\D+/g, '') : currentItem();
var itemIndex = (config('row_index_from_one') == 'true') ? row - 1 : row;
selectItems(itemIndex);
copy(\"application/x-copyq-item\", pack(getItem(itemIndex)));"
InMenu=true
Icon=\xf0cb
Shortcut=ctrl+1, ctrl+2, ctrl+3, ctrl+4, ctrl+5, ctrl+6, ctrl+7, ctrl+8, ctrl+9, ctrl+0
Edit Files
~~~~~~~~~~
Opens files referenced by selected item in external editor (uses
"External editor command" from "History" config tab).
Works with following path formats (some editors may not support all of
these).
- ``C:/...``
- ``file://...``
- ``~...`` (some shells)
- ``%...%...`` (Windows environment variables)
- ``$...`` (environment variables)
- ``/c/...`` (gitbash)
.. code-block:: ini
[Command]
Name=Edit Files
Match=^([a-zA-Z]:[\\\\/]|~|file://|%\\w+%|$\\w+|/)
Command="
copyq:
var editor = config('editor')
.replace(/ %1/, '')
var filePaths = str(input())
.replace(/^file:\\/{2}/gm, '')
.replace(/^\\/(\\w):?\\//gm, '$1:/')
.split('\\n')
var args = [editor].concat(filePaths)
execute.apply(this, args)"
Input=text/plain
InMenu=true
Icon=\xf040
Shortcut=f4
Change Monitoring State Permanently
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Disables clipboard monitoring permanently, i.e. the state is restored
when clipboard changes even after application is restarted.
Should be the first automatic command in the list of commands so other
commands are not invoked.
.. code-block:: ini
[Command]
Automatic=true
Command="
copyq:
var option = 'disable_monitoring'
var disabled = str(settings(option)) === 'true'
if (str(data('application/x-copyq-shortcut'))) {
disabled = !disabled
settings(option, disabled)
popup('', disabled ? 'Monitoring disabled' : 'Monitoring enabled')
}
if (disabled) {
disable()
ignore()
} else {
enable()
}"
GlobalShortcut=meta+alt+x
Icon=\xf05e
Name=Toggle Monitoring
Show Window Title
~~~~~~~~~~~~~~~~~
Shows source application window title for new items in tag ("Tags"
plugin must be enabled in "Items" config tab).
.. code-block:: ini
[Command]
Automatic=true
Command="
copyq:
var window = str(data('application/x-copyq-owner-window-title'))
var tagsMime = 'application/x-copyq-tags'
var tags = str(data(tagsMime)) + ', ' + window
setData(tagsMime, tags)"
Icon=\xf009
Name=Store Window Title
Show Copy Time
~~~~~~~~~~~~~~
Shows copy time of new items in tag ("Tags" plugin must be enabled in
"Items" config tab).
.. code-block:: ini
[Command]
Automatic=true
Command="
copyq:
var time = dateString('yyyy-MM-dd hh:mm:ss')
setData('application/x-copyq-user-copy-time', time)
var tagsMime = 'application/x-copyq-tags'
var tags = str(data(tagsMime)) + ', ' + time
setData(tagsMime, tags)"
Icon=\xf017
Name=Store Copy Time
Mark Selected Items
~~~~~~~~~~~~~~~~~~~
Toggles highlighting of selected items.
.. code-block:: ini
[Command]
Command="
copyq:
var color = 'rgba(255, 255, 0, 0.5)'
var mime = 'application/x-copyq-color'
var firstSelectedItem = selectedItems()[0]
var currentColor = str(read(mime, firstSelectedItem))
if (currentColor != color)
setData(mime, color)
else
removeData(mime)"
Icon=\xf1fc
InMenu=true
Name=Mark/Unmark Items
Shortcut=ctrl+m
Change Upper/Lower Case of Selected Text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: ini
[Command]
Command="
copyq:
if (!copy())
abort()
var text = str(clipboard())
var newText = text.toUpperCase()
if (text == newText)
newText = text.toLowerCase()
if (text == newText)
abort();
copy(newText)
paste()"
GlobalShortcut=meta+ctrl+u
Icon=\xf034
Name=Toggle Upper/Lower Case
Change Copied Text to Title Case
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: ini
[Command]
Name=Paste as title case
Command="
copyq:
function toTitleCase(str) {
return str.replace(
/\\w\\S*/g,
function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
);
}
copy(toTitleCase(str(input())))
paste()
"
Input=text/plain
IsGlobalShortcut=true
HideWindow=true
Icon=\xf15b
GlobalShortcut=meta+ctrl+t
|