This file is indexed.

/usr/share/doc/copyq/html/writing-commands-and-adding-functionality.html is in copyq-doc 3.2.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Writing Commands and Adding Functionality &mdash; CopyQ  documentation</title>
  

  
  
    <link rel="shortcut icon" href="_static/icon_32x32.png"/>
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="genindex.html"/>
        <link rel="search" title="Search" href="search.html"/>
    <link rel="top" title="CopyQ  documentation" href="index.html"/>
        <link rel="next" title="Scripting" href="scripting.html"/>
        <link rel="prev" title="Synchronize with Documents" href="synchronize.html"/> 

  
  <script src="_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="index.html" class="icon icon-home"> CopyQ
          

          
            
            <img src="_static/icon_64x64.png" class="logo" />
          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">The Basics</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="basic-usage.html">Basic Usage</a></li>
<li class="toctree-l1"><a class="reference internal" href="tabs-and-items.html">Tabs and Items</a></li>
<li class="toctree-l1"><a class="reference internal" href="keyboard.html">Keyboard</a></li>
<li class="toctree-l1"><a class="reference internal" href="images.html">Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="tags.html">Tags</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">FAQ - Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="glossary.html">Glossary</a></li>
</ul>
<p class="caption"><span class="caption-text">Advanced Topics</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="command-line.html">Command Line</a></li>
<li class="toctree-l1"><a class="reference internal" href="sessions.html">Sessions</a></li>
<li class="toctree-l1"><a class="reference internal" href="pin-items.html">Pin Items</a></li>
<li class="toctree-l1"><a class="reference internal" href="password-protection.html">Password Protection</a></li>
<li class="toctree-l1"><a class="reference internal" href="synchronize.html">Synchronize with Documents</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Writing Commands and Adding Functionality</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#command-dialog">Command Dialog</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#create-new-command">Create New Command</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#command-options">Command Options</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#save-and-share-commands">Save and Share Commands</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="scripting.html">Scripting</a></li>
<li class="toctree-l1"><a class="reference internal" href="command-examples.html">Command Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="backup.html">Backup</a></li>
<li class="toctree-l1"><a class="reference internal" href="writing-raw-data.html">Writing Raw Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="scripting-api.html">Scripting API</a></li>
</ul>
<p class="caption"><span class="caption-text">Development</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="build-source-code.html">Build from Source Code</a></li>
<li class="toctree-l1"><a class="reference internal" href="fixing-bugs.html">Fixing Bugs and Adding Features</a></li>
<li class="toctree-l1"><a class="reference internal" href="source-code-overview.html">Source Code Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="translations.html">Translations</a></li>
<li class="toctree-l1"><a class="reference internal" href="text-encoding.html">Text Encoding</a></li>
<li class="toctree-l1"><a class="reference internal" href="customize-and-build-the-windows-installer.html">Customize and Build the Windows Installer</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">CopyQ</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>Writing Commands and Adding Functionality</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/writing-commands-and-adding-functionality.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="writing-commands-and-adding-functionality">
<span id="writing-commands"></span><h1>Writing Commands and Adding Functionality<a class="headerlink" href="#writing-commands-and-adding-functionality" title="Permalink to this headline"></a></h1>
<p>CopyQ allows you to extend its functionality through commands in
following ways.</p>
<ol class="arabic simple">
<li>Add custom commands to context menu for selected items in history.</li>
<li>Run custom commands automatically when clipboard changes.</li>
<li>Assign global/system-wide shortcuts to custom commands.</li>
</ol>
<p>Here are some examples what can be achieved by using commands.</p>
<ul class="simple">
<li>Automatically store web links or other types of clipboard content in
special tabs to keep the history clean.</li>
<li>Paste current date and time or modified clipboard on a global
shortcut.</li>
<li>Pass selected items or clipboard to external application (e.g. web
browser or image editor).</li>
<li>Keep TODO lists and tag items as “important” or use custom tags.</li>
<li>See <a class="reference internal" href="command-examples.html#command-examples"><span class="std std-ref">Command Examples</span></a> for some other ideas and useful commands.</li>
</ul>
<div class="section" id="command-dialog">
<h2>Command Dialog<a class="headerlink" href="#command-dialog" title="Permalink to this headline"></a></h2>
<p>You can create new commands in Command dialog. To open the dialog
either:</p>
<ul class="simple">
<li>press default shortcut F6 or</li>
<li>select menu item “Commands/Global Shortcuts…” in “File” menu.</li>
</ul>
<p>Command dialog contains:</p>
<ul class="simple">
<li>list of custom commands on the left,</li>
<li>settings for currently selected command on the right,</li>
<li>command filter text field at the top,</li>
<li>buttons to modify the command list (add, remove and move commands) at the top,</li>
<li>buttons to save, load, copy and paste commands at the bottom.</li>
</ul>
<div class="section" id="create-new-command">
<h3>Create New Command<a class="headerlink" href="#create-new-command" title="Permalink to this headline"></a></h3>
<p>To create new command click the “Add” button in Command dialog. This
opens list with predefined commands.</p>
<p>“New Command” creates new empty command (but it won’t do anything
without being configured). One of the most frequently used predefined
command is “Show/hide main window” which allows you to assign global
shortcut for showing and hiding CopyQ window.</p>
<p>If you double click a predefined command (or select one or multiple
commands and click OK) it will be added to list of commands. The right
part of the Command dialog now shows the configuration for the new
command.</p>
<p>For example, for the “Show/hide main window” you’ll most likely need to
change only the “Global Shortcut” option so click on the button next to
it and press the shortcut you want to assign.</p>
<p>Commands can be quickly disabled by clicking the check box next to them
in command list.</p>
<p>By clicking on “OK” or “Apply” button in the dialog all commands will be
saved permanently.</p>
<div class="section" id="command-options">
<h4>Command Options<a class="headerlink" href="#command-options" title="Permalink to this headline"></a></h4>
<p>The following options can be set for commands.</p>
<p>If unsure what an option does, hover mouse pointer over it and tool tip
with description will appear.</p>
<div class="section" id="name">
<h5>Name<a class="headerlink" href="#name" title="Permalink to this headline"></a></h5>
<p>Name of the command. This is used in context menu if “In Menu” check box
is enabled. Use <code class="docutils literal"><span class="pre">/</span></code> in the name to create sub-menus.</p>
</div>
<div class="section" id="group-type-of-action">
<h5>Group: Type of Action<a class="headerlink" href="#group-type-of-action" title="Permalink to this headline"></a></h5>
<p>This group sets the main type of the command. Usually only one
sub-option is set.</p>
<div class="section" id="a-automatic">
<h6>a. Automatic<a class="headerlink" href="#a-automatic" title="Permalink to this headline"></a></h6>
<p>If enabled, the command is triggered whenever clipboard changes.</p>
<p>Automatic items are run in order they appear in the command list. No
other automatic commands will be run if a triggered automatic command
has “Remove Item” option set or calls <code class="docutils literal"><span class="pre">copyq</span> <span class="pre">ignore</span></code>.</p>
<p>The command is <strong>applied on current clipboard data</strong> - i.e. options
below access text or other data in clipboard.</p>
</div>
<div class="section" id="b-in-menu">
<h6>b. In Menu<a class="headerlink" href="#b-in-menu" title="Permalink to this headline"></a></h6>
<p>If enabled, the command can be run from main window either with
application shortcut, from context menu or “Item” menu. The command can
be also run from tray menu.</p>
<p>Shortcuts can be assigned by clicking on the button next to the option.
These <strong>application shortcuts work only while CopyQ window has focus</strong>.</p>
<p>If the command is run from <strong>tray menu</strong>, it is <strong>applied on clipboard
data</strong>, otherwise it’s <strong>applied on data in selected items</strong>.</p>
</div>
<div class="section" id="c-global-shortcut">
<h6>c. Global Shortcut<a class="headerlink" href="#c-global-shortcut" title="Permalink to this headline"></a></h6>
<p>Global or system shortcut is a keyboard shortcut that <strong>works even if the main
application window is not focused</strong>.</p>
<p>If enabled, the command is triggered whenever assigned shortcut is pressed.</p>
<p>This command is <strong>not applied on data</strong> in clipboard nor selected items.</p>
</div>
</div>
<div class="section" id="group-match-items">
<h5>Group: Match Items<a class="headerlink" href="#group-match-items" title="Permalink to this headline"></a></h5>
<p>This group is visible only for “Automatic” or “In Menu” commands.
Sub-options specify when the command can be used.</p>
<div class="section" id="content">
<h6>1. Content<a class="headerlink" href="#content" title="Permalink to this headline"></a></h6>
<p><a class="reference external" href="https://doc.qt.io/qt-4.8/qregexp.html#introduction">Regular expression</a>
to match text of selected items (for “In Menu” command) or clipboard
(for “Automatic” command).</p>
<p>For example, <code class="docutils literal"><span class="pre">^https?://</span></code> will match simple web addresses (text
starting with <code class="docutils literal"><span class="pre">http://</span></code> or <code class="docutils literal"><span class="pre">https://</span></code>).</p>
</div>
<div class="section" id="window">
<h6>2. Window<a class="headerlink" href="#window" title="Permalink to this headline"></a></h6>
<p><a class="reference external" href="https://doc.qt.io/qt-4.8/qregexp.html#introduction">Regular expression</a>
to match window title of active window (only for “Automatic” command).</p>
<p>For example, <code class="docutils literal"><span class="pre">-</span> <span class="pre">Chromium$</span></code> or <code class="docutils literal"><span class="pre">Mozilla</span> <span class="pre">Firefox$</span></code> to match some web
browser window titles (<code class="docutils literal"><span class="pre">$</span></code> in the expression means end of the title).</p>
</div>
<div class="section" id="filter">
<h6>3. Filter<a class="headerlink" href="#filter" title="Permalink to this headline"></a></h6>
<p>A command for validating text of selected items (for “In Menu” command)
or clipboard (for “Automatic” command).</p>
<p>If the command exits with non-zero exit code it won’t be shown in
context menu and automatically triggered on clipboard change.</p>
<p>Example, <code class="docutils literal"><span class="pre">copyq:</span> <span class="pre">if</span> <span class="pre">(tab().indexOf(&quot;Web&quot;)</span> <span class="pre">==</span> <span class="pre">-1)</span> <span class="pre">fail()</span></code> triggers the
command only if tab “Web” is available.</p>
</div>
<div class="section" id="format">
<h6>4. Format<a class="headerlink" href="#format" title="Permalink to this headline"></a></h6>
<p>Match format of selected items or clipboard.</p>
<p>The data of this format will be sent to <strong>standard input</strong> of the
command - this doesn’t apply if the command is triggered with global
shortcut.</p>
</div>
</div>
<div class="section" id="command">
<h5>Command<a class="headerlink" href="#command" title="Permalink to this headline"></a></h5>
<p>The command to run.</p>
<p>This can contain either:</p>
<ul class="simple">
<li>simple command line (e.g. <code class="docutils literal"><span class="pre">copyq</span> <span class="pre">popup</span> <span class="pre">%1</span></code> - expression <code class="docutils literal"><span class="pre">%1</span></code> means text of the selected item or clipboard),</li>
<li>input for command interpreter (prefixed with <code class="docutils literal"><span class="pre">bash:</span></code>, <code class="docutils literal"><span class="pre">powershell:</span></code>, <code class="docutils literal"><span class="pre">python:</span></code> etc.) or</li>
<li>CopyQ script (prefixed with <code class="docutils literal"><span class="pre">copyq:</span></code>).</li>
</ul>
<p>You can use <code class="docutils literal"><span class="pre">COPYQ</span></code> environment variable to get path of application
binary.</p>
<p>Current CopyQ session name is stored in <code class="docutils literal"><span class="pre">COPYQ_SESSION_NAME</span></code>
environment variable (see <a class="reference internal" href="sessions.html#sessions"><span class="std std-ref">Sessions</span></a>).</p>
<p>Example (call CopyQ from Python):</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">python</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">call</span>
<span class="n">copyq</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;COPYQ&#39;</span><span class="p">]</span>
<span class="n">call</span><span class="p">([</span><span class="n">copyq</span><span class="p">,</span> <span class="s1">&#39;read&#39;</span><span class="p">,</span> <span class="s1">&#39;0&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>Example (call CopyQ from PowerShell on Windows):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>powershell:
$Item1 = (&amp; &quot;$env:COPYQ&quot; read 0 | Out-String)
echo &quot;First item: $Item1&quot;
</pre></div>
</div>
</div>
<div class="section" id="group-action">
<h5>Group: Action<a class="headerlink" href="#group-action" title="Permalink to this headline"></a></h5>
<p>This group is visible only for “Automatic” or “In Menu” commands.</p>
<div class="section" id="copy-to-tab">
<h6>1. Copy to tab<a class="headerlink" href="#copy-to-tab" title="Permalink to this headline"></a></h6>
<p>Creates new item in given tab.</p>
</div>
<div class="section" id="remove-item">
<h6>2. Remove Item<a class="headerlink" href="#remove-item" title="Permalink to this headline"></a></h6>
<p>Removes selected items. If enabled for “Automatic” command, the
clipboard will be ignored and no other automatic commands will be
executed.</p>
</div>
</div>
<div class="section" id="group-menu-action">
<h5>Group: Menu Action<a class="headerlink" href="#group-menu-action" title="Permalink to this headline"></a></h5>
<p>This group is visible only for “In Menu” commands.</p>
<div class="section" id="hide-main-window-after-activation">
<h6>1. Hide main window after activation<a class="headerlink" href="#hide-main-window-after-activation" title="Permalink to this headline"></a></h6>
<p>If enabled, main window will be hidden after the command is executed.</p>
</div>
</div>
<div class="section" id="group-command-options">
<h5>Group: Command options<a class="headerlink" href="#group-command-options" title="Permalink to this headline"></a></h5>
<p>This group is visible only for “Automatic” or “In Menu” commands.</p>
<div class="section" id="wait">
<h6>1. Wait<a class="headerlink" href="#wait" title="Permalink to this headline"></a></h6>
<p>Show action dialog before applying options below.</p>
</div>
<div class="section" id="transform">
<h6>2. Transform<a class="headerlink" href="#transform" title="Permalink to this headline"></a></h6>
<p>Modify selected items - i.e. remove them and replace with <strong>standard
output</strong> of the command.</p>
</div>
<div class="section" id="output">
<h6>3. Output<a class="headerlink" href="#output" title="Permalink to this headline"></a></h6>
<p>Format of <strong>standard output</strong> to save as new item.</p>
</div>
<div class="section" id="separator">
<h6>4. Separator<a class="headerlink" href="#separator" title="Permalink to this headline"></a></h6>
<p>Separator for splitting output to multiple items (<code class="docutils literal"><span class="pre">\n</span></code> to split
lines).</p>
</div>
<div class="section" id="output-tab">
<h6>5. Output tab<a class="headerlink" href="#output-tab" title="Permalink to this headline"></a></h6>
<p>Tab for saving the output of command.</p>
</div>
</div>
</div>
</div>
<div class="section" id="save-and-share-commands">
<h3>Save and Share Commands<a class="headerlink" href="#save-and-share-commands" title="Permalink to this headline"></a></h3>
<p>You can back up or share commands by saving them in a file (“Save
Selected Commands…” button) or by copying them to clipboard.</p>
<p>The saved commands can be loaded back to command list (“Load
Commands…” button) or pasted to the list from clipboard.</p>
<p>You can try some examples by copying commands from <a class="reference internal" href="command-examples.html#command-examples"><span class="std std-ref">Command Examples</span></a>.</p>
</div>
</div>
</div>


           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="scripting.html" class="btn btn-neutral float-right" title="Scripting" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="synchronize.html" class="btn btn-neutral" title="Synchronize with Documents" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Lukas Holecek.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'./',
            VERSION:'',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="_static/jquery.js"></script>
      <script type="text/javascript" src="_static/underscore.js"></script>
      <script type="text/javascript" src="_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>