Debian Codegraph @

docs/scripting-api.rst

raw
1 .. _scripting-api:
2
3 Scripting API
4 =============
5
6 CopyQ provides scripting capabilities to automatically handle clipboard
7 changes, organize items, change settings and much more.
8
9 Supported language features and functions can be found at `ECMAScript Reference
10 <https://doc.qt.io/qt-6/qtqml-javascript-functionlist.html>`__. The language is
11 mostly equivalent to modern JavaScript. Some features may be missing but feel
12 free to use for example `JavaScript reference on MDN
13 <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/>`__.
14
15 CopyQ-specific features described in this document:
16
17 - `Functions`_
18 - `Types`_
19 - `Objects`_
20 - `MIME types`_
21 - `Plugins`_
22
23 .. note::
24
25 These terms are equivalent: format, MIME type, media type
26
27 Execute Script
28 --------------
29
30 The scripts can be executed from:
31
32 a. Action or Command dialogs (F5, F6 shortcuts), if
33 the first line starts with ``copyq:``
34 b. command line as ``copyq eval '<SCRIPT>'``
35 c. command line as ``cat script.js | copyq eval -``
36 d. command line as
37 ``copyq <SCRIPT_FUNCTION> <FUNCTION_ARGUMENT_1> <FUNCTION_ARGUMENT_2> ...``
38
39 When run from command line, result of last expression is printed on
40 stdout.
41
42 Command exit values are:
43
44 - 0 - script finished without error
45 - 1 - :js:func:`fail` was called
46 - 2 - bad syntax
47 - 3 - exception was thrown
48
49 Command Line
50 ------------
51
52 If number of arguments that can be passed to function is limited you can
53 use
54
55 .. code-block:: bash
56
57 copyq <FUNCTION1> <FUNCTION1_ARGUMENT_1> <FUNCTION1_ARGUMENT_2> \
58 <FUNCTION2> <FUNCTION2_ARGUMENT> \
59 <FUNCTION3> <FUNCTION3_ARGUMENTS> ...
60
61 where ``<FUNCTION1>`` and ``<FUNCTION2>`` are scripts where result of
62 last expression is functions that take two and one arguments
63 respectively.
64
65 Example:
66
67 .. code-block:: bash
68
69 copyq tab clipboard separator "," read 0 1 2
70
71 After :js:func:`eval` no arguments are treated as functions since it can access
72 all arguments.
73
74 Arguments recognize escape sequences ``\n`` (new line), ``\t``
75 (tabulator character) and ``\\`` (backslash).
76
77 Argument ``-e`` is identical to :js:func:`eval`.
78
79 Argument ``-`` is replaced with data read from stdin.
80
81 Argument ``--`` is skipped and all the remaining arguments are
82 interpreted as they are (escape sequences are ignored and ``-e``, ``-``,
83 ``--`` are left unchanged).
84
85 Functions
86 ---------
87
88 Argument list parts ``...`` and ``[...]`` are optional and can be
89 omitted.
90
91 Comment `/*set*/` in function declaration indicates a specific function
92 overload.
93
94 Item **row** values in scripts always **start from 0** (like array index),
95 unlike in GUI, where row numbers start from 1 by default.
96
97 .. js:function:: version()
98
99 Returns versions, features and host system information.
100
101 :returns: Versions, features and host system information
102 :rtype: string
103
104 Example return value::
105
106 CopyQ Clipboard Manager 14.0.0.14-g0e004828
107 Arch: x86_64-little_endian-lp64
108 Audio: miniaudio 0.11.25
109 Compiler: GCC
110 DISPLAY: :0
111 KGuiAddons: 6.24.0
112 KNotifications: 6.24.0
113 KStatusNotifierItem: 6.24.0
114 OS: Fedora Linux 43 (Workstation Edition)
115 QCA: 2.3.10
116 Qt: 6.10.2
117 QtKeychain: 0.15.0
118 WAYLAND_DISPLAY: wayland-0
119 XDG_CURRENT_DESKTOP: KDE
120 XDG_SESSION_DESKTOP: KDE
121 XDG_SESSION_TYPE: wayland
122 has-audio: 1
123 has-encryption: 1
124 has-global-shortcuts: 1
125 has-keychain: 1
126 has-mouse-selection: 1
127 platform: Linux/X11
128
129 .. js:function:: help()
130
131 Returns help string.
132
133 :returns: Help string.
134 :rtype: string
135
136 .. js:function:: /*search*/ help(searchString, ...)
137
138 Returns help for matched commands.
139
140 :returns: Help string.
141 :rtype: string
142
143 .. js:function:: show()
144
145 Shows main window.
146
147 This uses the last window position and size which is updated whenever the
148 window is moved or resized.
149
150 .. js:function:: /*tab*/ show(tabName)
151
152 Shows tab.
153
154 This uses the last window position and size which is updated whenever the
155 window is moved or resized.
156
157 .. js:function:: showAt(x, y, [width, height])
158
159 Shows main window with given geometry.
160
161 The new window position and size will not be stored for ``show()``.
162
163 .. js:function:: /*cursor*/ showAt()
164
165 Shows main window under mouse cursor.
166
167 The new window position will not be stored for ``show()``.
168
169 .. js:function:: /*tab*/ showAt(x, y, width, height, tabName)
170
171 Shows tab with given geometry.
172
173 The new window position and size will not be stored for ``show()``.
174
175 .. js:function:: hide()
176
177 Hides main window.
178
179 .. js:function:: toggle()
180
181 Shows or hides main window.
182
183 This uses the last window position and size which is updated whenever the
184 window is moved or resized.
185
186 :returns: ``true`` only if main window is being shown, otherwise ``false``.
187 :rtype: bool
188
189 .. js:function:: menu()
190
191 Opens context menu.
192
193 .. js:function:: /*tab*/ menu(tabName, [maxItemCount, [x, y]])
194
195 Shows context menu for given tab.
196
197 This menu doesn't show clipboard and doesn't have any special actions.
198
199 Second argument is optional maximum number of items. The default value
200 same as for tray (i.e. value of ``config('tray_items')``).
201
202 Optional arguments x, y are coordinates in pixels on screen where menu
203 should show up. By default menu shows up under the mouse cursor.
204
205 .. js:function:: exit()
206
207 Exits server.
208
209 .. js:function:: disable()
210 enable()
211
212 Disables or enables clipboard content storing.
213
214 .. js:function:: monitoring()
215
216 Returns true only if clipboard storing is enabled.
217
218 :returns: ``true`` if clipboard storing is enabled, otherwise ``false``.
219 :rtype: bool
220
221 .. js:function:: visible()
222
223 Returns true only if main window is visible.
224
225 :returns: ``true`` if main window is visible, otherwise ``false``.
226 :rtype: bool
227
228 .. js:function:: focused()
229
230 Returns true only if main window has focus.
231
232 :returns: ``true`` if main window has focus, otherwise ``false``.
233 :rtype: bool
234
235 .. js:function:: focusPrevious()
236
237 Activates window that was focused before the main window.
238
239 :throws Error: Thrown if previous window cannot be activated.
240
241 .. js:function:: preview([true|false])
242
243 Shows/hides item preview and returns true only if preview was visible.
244
245 Example -- toggle the preview:
246
247 .. code-block:: js
248
249 preview(false) || preview(true)
250
251 .. js:function:: filter()
252
253 Returns the current text for filtering items in main window.
254
255 :returns: Current filter.
256 :rtype: string
257
258 .. js:function:: /*set*/ filter(filterText)
259
260 Sets text for filtering items in main window.
261
262 .. js:function:: ignore()
263
264 Ignores current clipboard content (used for automatic commands).
265
266 This does all of the below.
267
268 - Skips any next automatic commands.
269 - Omits changing window title and tray tool tip.
270 - Won't store content in clipboard tab.
271
272 .. js:function:: clipboard([mimeType])
273
274 Returns clipboard data for MIME type (default is text).
275
276 Pass argument ``"?"`` to list available MIME types.
277
278 :returns: Clipboard data.
279 :rtype: :js:class:`ByteArray`
280
281 .. js:function:: selection([mimeType])
282
283 Same as :js:func:`clipboard` for `primary selection`_.
284
285 :returns: Selection data.
286 :rtype: :js:class:`ByteArray`
287
288 .. js:function:: hasClipboardFormat(mimeType)
289
290 Returns true only if clipboard contains MIME type.
291
292 :returns: ``true`` if clipboard contains the format, otherwise ``false``.
293 :rtype: bool
294
295 .. js:function:: hasSelectionFormat(mimeType)
296
297 Same as :js:func:`hasClipboardFormat` for `primary selection`_.
298
299 :returns: ``true`` if selection contains the format, otherwise ``false``.
300 :rtype: bool
301
302 .. js:function:: isClipboard()
303
304 Returns true only in automatic command triggered by clipboard change.
305
306 This can be used to check if current automatic command was triggered by
307 clipboard and not `primary selection`_ change.
308
309 :returns: ``true`` if current automatic command is triggered by clipboard
310 change, otherwise ``false``.
311 :rtype: bool
312
313 .. js:function:: copy(text)
314
315 Sets clipboard plain text.
316
317 Same as ``copy(mimeText, text)``.
318
319 :throws Error: Thrown if clipboard fails to be set.
320
321 .. js:function:: /*data*/ copy(mimeType, data, [mimeType, data]...)
322
323 Sets clipboard data.
324
325 This also sets :js:data:`mimeOwner` format so automatic commands are not run
326 on the new data and it's not stored in clipboard tab.
327
328 All other data formats are dropped from clipboard.
329
330 :throws Error: Thrown if clipboard fails to be set.
331
332 Example -- set both text and rich text:
333
334 .. code-block:: js
335
336 copy(mimeText, 'Hello, World!',
337 mimeHtml, '<p>Hello, World!</p>')
338
339 .. js:function:: /*item*/ copy(Item)
340
341 Function override with an item argument.
342
343 :throws Error: Thrown if clipboard fails to be set.
344
345 Example -- set both text and rich text:
346
347 .. code-block:: js
348
349 var item = {}
350 item[mimeText] = 'Hello, World!'
351 item[mimeHtml] = '<p>Hello, World!</p>'
352 copy(item)
353
354 .. js:function:: /*window*/ copy()
355
356 Sends ``Ctrl+C`` to the current application or window to trigger a copy
357 operation.
358
359 The function resets the clipboard before sending the shortcut so it can
360 detect changes properly.
361
362 :throws Error: Thrown if the clipboard does not change. This can indicate
363 that sending the shortcut failed, the target current window could not be
364 retrieved, or that nothing valid was selected to copy. In such case, see
365 logs for more details.
366
367 Example:
368
369 .. code-block:: js
370
371 try {
372 copy()
373 } catch (e) {
374 popup('Copying Failed', e)
375 abort()
376 }
377 let text = str(clipboard())
378 popup('Copied Text', text)
379
380 .. js:function:: copySelection(text)
381
382 Sets primary selection plain text.
383
384 Equivalent to ``copy(text)`` but for `primary selection`_.
385
386 :throws Error: Thrown if selection fails to be set.
387
388 .. js:function:: /*data*/ copySelection(mimeType, data, [mimeType, data]...)
389
390 Sets primary selection data.
391
392 Equivalent to ``copy(mimeType, data, ...)`` but for `primary selection`_.
393
394 :throws Error: Thrown if selection fails to be set.
395
396 .. js:function:: /*item*/ copySelection(Item)
397
398 Sets primary selection from an item.
399
400 Equivalent to ``copy(Item)`` but for `primary selection`_.
401
402 :throws Error: Thrown if selection fails to be set.
403
404 .. js:function:: paste()
405
406 Sends ``Shift+Insert`` (or ``Ctrl+V``) to the current application or window
407 to trigger a paste operation.
408
409 If the regular expression in the option ``window_paste_with_ctrl_v_regex``
410 matches the current window title, the shortcut ``Ctrl+V`` is sent instead of
411 the default ``Shift+Insert``. For example, to override the option so that
412 ``Ctrl+V`` is sent for all windows, call:
413
414 .. code-block:: js
415
416 config('window_paste_with_ctrl_v_regex', '.*')
417
418 Correct functionality depends a lot on target application and window
419 manager.
420
421 :throws Error: Thrown if paste operation fails. This can indicate that
422 sending the shortcut failed, the target current window could not be
423 retrieved. In such case, see logs for more details.
424
425 Example:
426
427 .. code-block:: js
428
429 copy(text)
430 try {
431 paste()
432 } catch (e) {
433 popup('Pasting Failed', e)
434 abort()
435 }
436 popup('Pasting Successful')
437
438 .. js:function:: tab()
439
440 Returns tab names.
441
442 :returns: Array with names of existing tab.
443 :rtype: array of strings
444
445 .. js:function:: /*set*/ tab(tabName)
446
447 Sets current tab for the script.
448
449 Example -- select third item at index 2 from tab "Notes":
450
451 .. code-block:: js
452
453 tab('Notes')
454 select(2)
455
456 .. js:function:: removeTab(tabName)
457
458 Removes tab.
459
460 .. js:function:: renameTab(tabName, newTabName)
461
462 Renames tab.
463
464 .. js:function:: tabIcon(tabName)
465
466 Returns path to icon for tab.
467
468 :returns: Path to icon for tab.
469 :rtype: string
470
471 .. js:function:: /*set*/ tabIcon(tabName, iconPath)
472
473 Sets icon for tab.
474
475 .. js:function:: unload([tabNames...])
476
477 Unload tabs (i.e. items from memory).
478
479 If no tabs are specified, unloads all tabs.
480
481 If a tab is open and visible or has an editor open, it won't be unloaded.
482
483 :returns: Array of successfully unloaded tabs.
484 :rtype: array of strings
485
486 .. js:function:: forceUnload([tabNames...])
487
488 Force-unload tabs (i.e. items from memory).
489
490 If no tabs are specified, unloads all tabs.
491
492 Refresh button needs to be clicked to show the content of a force-unloaded
493 tab.
494
495 If a tab has an editor open, the editor will be closed first even if it has
496 unsaved changes.
497
498 .. js:function:: count()
499 length()
500 size()
501
502 Returns amount of items in current tab.
503
504 :returns: Item count.
505 :rtype: int
506
507 .. js:function:: select(row)
508
509 Copies item in the row to clipboard.
510
511 Additionally, moves selected item to top depending on settings.
512
513 .. js:function:: next()
514
515 Copies next item from current tab to clipboard.
516
517 .. js:function:: previous()
518
519 Copies previous item from current tab to clipboard.
520
521 .. js:function:: add(text|Item...)
522
523 Same as ``insert(0, ...)``.
524
525 .. js:function:: insert(row, text|Item...)
526
527 Inserts new items to current tab.
528
529 :throws Error: Thrown if space for the items cannot be allocated.
530
531 .. js:function:: remove(row, ...)
532
533 Removes items in current tab.
534
535 :throws Error: Thrown if some items cannot be removed.
536
537 .. js:function:: move(row)
538
539 Moves selected items to given row in same tab.
540
541 .. js:function:: edit([row|text] ...)
542
543 Edits items in the current tab.
544
545 Opens external editor if set, otherwise opens internal editor.
546
547 If row is -1 (or other negative number) edits clipboard instead
548 and creates new item.
549
550 .. js:function:: editItem(row, [mimeType, [data]])
551
552 Edits specific format for the item.
553
554 Opens external editor if set, otherwise opens internal editor.
555
556 If row is -1 (or other negative number) edits clipboard instead
557 and creates new item.
558
559 .. js:function:: read([mimeType])
560
561 Same as :js:func:`clipboard`.
562
563 .. js:function:: /*row*/ read(mimeType, row, ...)
564
565 Returns concatenated data from items, or clipboard if row is negative.
566
567 Pass argument ``"?"`` to list available MIME types.
568
569 :returns: Concatenated data in the rows.
570 :rtype: :js:class:`ByteArray`
571
572 .. js:function:: write(row, mimeType, data, [mimeType, data]...)
573
574 Inserts new item to current tab.
575
576 :throws Error: Thrown if space for the items cannot be allocated.
577
578 .. js:function:: /*item*/ write(row, Item...)
579
580 Function override with one or more item arguments.
581
582 .. js:function:: /*items*/ write(row, Item[])
583
584 Function override with item list argument.
585
586 .. js:function:: change(row, mimeType, data, [mimeType, data]...)
587
588 Changes data in item in current tab.
589
590 If data is ``undefined`` the format is removed from item.
591
592 .. js:function:: /*item*/ change(row, Item...)
593
594 Function override with one or more item arguments.
595
596 .. js:function:: /*items*/ change(row, Item[])
597
598 Function override with item list argument.
599
600 .. js:function:: separator()
601
602 Returns item separator (used when concatenating item data).
603
604 :returns: Current separator.
605 :rtype: string
606
607 .. js:function:: /*set*/ separator(separator)
608
609 Sets item separator for concatenating item data.
610
611 .. js:function:: action()
612
613 Opens action dialog.
614
615 .. js:function:: /*row*/ action([rows, ...], command, [outputItemSeparator])
616
617 Runs command for items in current tab.
618
619 If rows arguments is specified, ``%1`` in the command will be replaced with
620 concatenated text of the rows. If a row is negative, the text is taken from
621 the clipboard.
622
623 If no rows are specified, ``%1`` in the command will be replaced with
624 clipboard text.
625
626 The concatenated text is also passed on standard input of the command.
627
628 .. js:function:: popup(title, message, [time=8000])
629
630 Shows popup message for given time in milliseconds.
631
632 If ``time`` argument is set to -1, the popup is hidden only after mouse
633 click.
634
635 .. js:function:: notification(...)
636
637 Shows popup message with icon and buttons.
638
639 Each button can have script and data.
640
641 If button is clicked the notification is hidden and script is executed
642 with the data passed as stdin.
643
644 The function returns immediately (doesn't wait on user input).
645
646 Special arguments:
647
648 - '.title' - notification title
649 - '.message' - notification message (can contain basic HTML)
650 - '.icon' - notification icon (path to image or font icon)
651 - '.id' - notification ID - this replaces notification with same ID
652 - '.time' - duration of notification in milliseconds (default is -1,
653 i.e. waits for mouse click)
654 - '.button' - adds button (three arguments: name, script and data)
655 - '.urgency' - sets notification urgency if it is supported; value can be:
656 'low', 'normal', 'high', 'critical'
657 - '.persistent' - enables/disables persistent notification if it is
658 supported; value can be ``true`` or ``false``
659
660 Example:
661
662 .. code-block:: js
663
664 notification(
665 '.title', 'Example',
666 '.message', 'Notification with button',
667 '.button', 'Cancel', '', '',
668 '.button', 'OK', 'copyq:popup(input())', 'OK Clicked'
669 )
670
671 .. js:function:: exportTab(fileName)
672
673 Exports current tab into file.
674
675 :throws Error: Thrown if export fails.
676
677 .. js:function:: importTab(fileName)
678
679 Imports items from file to a new tab.
680
681 :throws Error: Thrown if import fails.
682
683 .. js:function:: exportData(fileName)
684
685 Exports all tabs and configuration into file.
686
687 :throws Error: Thrown if export fails.
688
689 .. js:function:: importData(fileName)
690
691 Imports all tabs and configuration from file.
692
693 :throws Error: Thrown if import fails.
694
695 .. js:function:: config()
696
697 Returns help with list of available application options.
698
699 Users can change most of these options via the CopyQ GUI, mainly via
700 the "Preferences" window.
701
702 These options are persisted within the ``[Options]`` section of a corresponding
703 ``copyq.ini`` or ``copyq.conf`` file (``copyq.ini`` is used on Windows).
704
705 :returns: Available options.
706 :rtype: string
707
708 .. js:function:: /*get*/ config(optionName)
709
710 Returns value of given application option.
711
712 :returns: Current value of the option.
713 :rtype: string
714 :throws Error: Thrown if the option is invalid.
715
716 .. js:function:: /*set*/ config(optionName, value)
717
718 Sets application option and returns new value.
719
720 :returns: New value of the option.
721 :rtype: string
722 :throws Error: Thrown if the option is invalid.
723
724 .. js:function:: /*set-more*/ config(optionName, value, ...)
725
726 Sets multiple application options and return list with values in format
727 ``optionName=newValue``.
728
729 :returns: New values of the options.
730 :rtype: string
731 :throws Error: Thrown if there is an invalid option in which case it won't set
732 any options.
733
734 .. js:function:: toggleConfig(optionName)
735
736 Toggles an option (true to false and vice versa) and returns the new value.
737
738 :returns: New value of the option.
739 :rtype: bool
740
741 .. js:function:: info([pathName])
742
743 Returns diagnostic info: versions, features, platform, environment variables
744 and common paths.
745
746 On Linux, also includes environment variables: ``DISPLAY``,
747 ``WAYLAND_DISPLAY``, ``XDG_CURRENT_DESKTOP``, ``XDG_SESSION_DESKTOP``,
748 ``XDG_SESSION_TYPE``.
749
750 When called without arguments, non-path entries are listed first,
751 followed by paths at the end.
752
753 :returns: Path for given identifier.
754 :rtype: string
755
756 Example -- print path to the configuration file:
757
758 .. code-block:: js
759
760 info('config')
761 .. js:function:: eval(script)
762
763 Evaluates script and returns result.
764
765 :returns: Result of the last expression.
766
767 .. js:function:: source(fileName)
768
769 Evaluates script file and returns result of last expression in the script.
770
771 This is useful to move some common code out of commands.
772
773 :returns: Result of the last expression.
774
775 .. code-block:: js
776
777 // File: c:/copyq/replace_clipboard_text.js
778 replaceClipboardText = function(replaceWhat, replaceWith)
779 {
780 var text = str(clipboard())
781 var newText = text.replace(replaceWhat, replaceWith)
782 if (text != newText)
783 copy(newText)
784 }
785
786 .. code-block:: js
787
788 source('c:/copyq/replace_clipboard_text.js')
789 replaceClipboardText('secret', '*****')
790
791 .. js:function:: currentPath()
792
793 Get current path.
794
795 :returns: Current path.
796 :rtype: string
797
798 .. code-block:: bash
799
800 cd /tmp
801 copyq currentPath
802 # Prints: /tmp
803
804 .. js:function:: /*set*/ currentPath(path)
805
806 Set current path.
807
808 .. js:function:: str(value)
809
810 Converts a value to string.
811
812 If ByteArray object is the argument, it assumes UTF8 encoding. To use
813 different encoding, use :js:func`toUnicode`.
814
815 :returns: Value as string.
816 :rtype: string
817
818 .. js:function:: input()
819
820 Returns standard input passed to the script.
821
822 :returns: Data on stdin.
823 :rtype: :js:class:`ByteArray`
824
825 .. js:function:: toUnicode(ByteArray)
826
827 Returns string for bytes with encoding detected by checking Byte Order Mark (BOM).
828
829 :returns: Value as string.
830 :rtype: string
831
832 .. js:function:: /*encoding*/ toUnicode(ByteArray, encodingName)
833
834 Returns string for bytes with given encoding.
835
836 :returns: Value as string.
837 :rtype: string
838
839 .. js:function:: fromUnicode(String, encodingName)
840
841 Returns encoded text.
842
843 :returns: Value as ByteArray.
844 :rtype: :js:class:`ByteArray`
845
846 .. js:function:: data(mimeType)
847
848 Returns data for automatic commands or selected items.
849
850 If run from menu or using non-global shortcut the data are taken from
851 selected items.
852
853 If run for automatic command the data are clipboard content.
854
855 :returns: Data for the format.
856 :rtype: :js:class:`ByteArray`
857
858 .. js:function:: setData(mimeType, data)
859
860 Set data for automatic and display commands, or the current item selection.
861
862 Next automatic command will receive the updated data.
863
864 This is also the data used to create new item from clipboard.
865
866 :returns: ``true`` if data were set, ``false`` if parsing data failed (in
867 case of :js:data:`mimeItems`).
868 :rtype: bool
869
870 Example -- automatic command that adds a creation time data and tag to new
871 items:
872
873 ::
874
875 copyq:
876 var timeFormat = 'yyyy-MM-dd hh:mm:ss'
877 setData('application/x-copyq-user-copy-time', dateString(timeFormat))
878 setData(mimeTags, 'copied: ' + time)
879
880 Example -- menu command that adds a tag to selected items:
881
882 ::
883
884 copyq:
885 setData('application/x-copyq-tags', 'Important')
886
887 .. js:function:: removeData(mimeType)
888
889 Removes data for automatic and display commands, or the current item selection.
890
891 .. js:function:: dataFormats()
892
893 Returns formats available for :js:func:`data`.
894
895 :returns: Array of data formats.
896 :rtype: array of strings
897
898 .. js:function:: print(value)
899
900 Prints value to standard output.
901
902 .. js:function:: serverLog(value)
903
904 Prints value to application log.
905
906 .. js:function:: logs()
907
908 Returns application logs.
909
910 :returns: Application logs.
911 :rtype: ByteArray
912
913 .. js:function:: abort()
914
915 Aborts script evaluation.
916
917 .. js:function:: fail()
918
919 Aborts script evaluation with nonzero exit code.
920
921 .. js:function:: setCurrentTab(tabName)
922
923 Focus tab without showing main window.
924
925 .. js:function:: selectItems(row, ...)
926
927 Selects items in current tab.
928
929 .. js:function:: selectedTab()
930
931 Returns tab that was selected when script was executed.
932
933 :returns: Currently selected tab name (see `Selected Items`_).
934 :rtype: string
935
936 .. js:function:: selectedItems()
937
938 Returns selected rows in current tab.
939
940 :returns: Currently selected rows (see `Selected Items`_).
941 :rtype: array of ints
942
943 .. js:function:: selectedItemData(index)
944
945 Returns data for given selected item.
946
947 The data can empty if the item was removed during execution of the
948 script.
949
950 :returns: Currently selected items (see `Selected Items`_).
951 :rtype: array of :js:class:`Item`
952
953 .. js:function:: setSelectedItemData(index, Item)
954
955 Set data for given selected item.
956
957 Returns false only if the data cannot be set, usually if item was
958 removed.
959
960 See `Selected Items`_.
961
962 :returns: ``true`` if data were set, otherwise ``false``.
963 :rtype: bool
964
965 .. js:function:: selectedItemsData()
966
967 Returns data for all selected items.
968
969 Some data can be empty if the item was removed during execution of the
970 script.
971
972 :returns: Currently selected item data (see `Selected Items`_).
973 :rtype: array of :js:class:`Item`
974
975 .. js:function:: setSelectedItemsData(Item[])
976
977 Set data to all selected items.
978
979 Some data may not be set if the item was removed during execution of the
980 script.
981
982 See `Selected Items`_.
983
984 .. js:function:: currentItem()
985 index()
986
987 Returns current row in current tab.
988
989 See `Selected Items`_.
990
991 :returns: Current row (see `Selected Items`_).
992 :rtype: int
993
994 .. js:function:: escapeHtml(text)
995
996 Returns text with special HTML characters escaped.
997
998 :returns: Escaped HTML text.
999 :rtype: string
1000
1001 .. js:function:: unpack(data)
1002
1003 Returns deserialized object from serialized items.
1004
1005 :returns: Deserialize item.
1006 :rtype: :js:class:`Item`
1007
1008 .. js:function:: pack(Item)
1009
1010 Returns serialized item.
1011
1012 :returns: Serialize item.
1013 :rtype: :js:class:`ByteArray`
1014
1015 .. js:function:: getItem(row)
1016
1017 Returns an item in current tab.
1018
1019 :returns: Item data for the row.
1020 :rtype: :js:class:`Item`
1021
1022 Example -- show data of the first item in a tab in popups:
1023
1024 .. code-block:: js
1025
1026 tab('work') // change current tab for the script to 'work'
1027 var item = getItem(0)
1028 for (var format in item) {
1029 var data = item[format]
1030 popup(format, data)
1031 }
1032
1033 .. seealso::
1034
1035 - :js:func:`selectedItemsData`
1036
1037 .. js:function:: setItem(row, text|Item)
1038
1039 Inserts item to current tab.
1040
1041 Same as ``insert(row, something)``.
1042
1043 .. seealso::
1044
1045 - :js:func:`insert`
1046 - :js:func:`setSelectedItemsData`
1047
1048 .. js:function:: toBase64(data)
1049
1050 Returns base64-encoded data.
1051
1052 :returns: Base64-encoded data.
1053 :rtype: string
1054
1055 .. js:function:: fromBase64(base64String)
1056
1057 Returns base64-decoded data.
1058
1059 :returns: Base64-decoded data.
1060 :rtype: :js:class:`ByteArray`
1061
1062 .. js:function:: md5sum(data)
1063
1064 Returns MD5 checksum of data.
1065
1066 :returns: MD5 checksum of the data.
1067 :rtype: :js:class:`ByteArray`
1068
1069 .. js:function:: sha1sum(data)
1070
1071 Returns SHA1 checksum of data.
1072
1073 :returns: SHA1 checksum of the data.
1074 :rtype: :js:class:`ByteArray`
1075
1076 .. js:function:: sha256sum(data)
1077
1078 Returns SHA256 checksum of data.
1079
1080 :returns: SHA256 checksum of the data.
1081 :rtype: :js:class:`ByteArray`
1082
1083 .. js:function:: sha512sum(data)
1084
1085 Returns SHA512 checksum of data.
1086
1087 :returns: SHA512 checksum of the data.
1088 :rtype: :js:class:`ByteArray`
1089
1090 .. js:function:: open(url, ...)
1091
1092 Tries to open URLs in appropriate applications.
1093
1094 :returns: ``true`` if all URLs were successfully opened, otherwise ``false``.
1095 :rtype: bool
1096
1097 .. js:function:: execute(argument, ..., null, stdinData, ...)
1098
1099 Executes a command.
1100
1101 All arguments after ``null`` are passed to standard input of the
1102 command.
1103
1104 If argument is function it will be called with array of lines read from
1105 stdout whenever available.
1106
1107 An exception is thrown if executable was not found or could not be executed.
1108
1109 :returns: Finished command properties.
1110 :rtype: :js:class:`FinishedCommand`
1111
1112 Example -- create item for each line on stdout:
1113
1114 .. code-block:: js
1115
1116 execute('tail', '-f', 'some_file.log',
1117 function(lines) { add.apply(this, lines) })
1118
1119 Returns object for the finished command or ``undefined`` on failure.
1120
1121 .. js:function:: playSound(fileOrObject)
1122
1123 Plays audio file.
1124
1125 The argument can be a file path string or an object with ``file`` and
1126 optional ``volume`` properties.
1127
1128 Supports WAV, MP3 and FLAC formats. The function starts playback and
1129 returns immediately.
1130
1131 An exception is thrown if the file doesn't exist or cannot be played.
1132
1133 Requires the application to be built with audio capabilities. You can verify
1134 this with ``info('has-audio')``.
1135
1136 :param fileOrObject: Path to the audio file, or an object
1137 ``{file: 'path', volume: 50}``.
1138 :type fileOrObject: string or object
1139
1140 The ``volume`` property is a percentage (default ``100``). Values above
1141 ``100`` amplify the sound; the maximum is ``200``.
1142
1143 Example --- play a notification sound:
1144
1145 .. code-block:: js
1146
1147 playSound('/path/to/notification.wav')
1148
1149 Example --- play at 50% volume:
1150
1151 .. code-block:: js
1152
1153 playSound({file: '/path/to/notification.wav', volume: 50})
1154
1155
1156 .. js:function:: String currentWindowTitle()
1157
1158 Returns window title of currently focused window.
1159
1160 :returns: Current window title.
1161 :rtype: string
1162
1163 .. js:function:: String currentClipboardOwner()
1164
1165 Returns name of the current clipboard owner.
1166
1167 The default implementation returns `currentWindowTitle()`.
1168
1169 This is used to set `mimeWindowTitle` format for the clipboard data in
1170 automatic commands and filtering by window title.
1171
1172 Depending on the current system, option `update_clipboard_owner_delay_ms`
1173 can introduce a delay before any new owner value return by this function is
1174 used. The reason is to avoid using an incorrect clipboard owner from the
1175 current window title if the real clipboard owner set the clipboard after or
1176 just before hiding its window (like with some password managers).
1177
1178 :returns: Current clipboard owner name.
1179 :rtype: string
1180
1181 .. js:function:: dialog(...)
1182
1183 Shows messages or asks user for input.
1184
1185 Arguments are names and associated values.
1186
1187 Special arguments:
1188
1189 - '.title' - dialog title
1190 - '.icon' - dialog icon (see below for more info)
1191 - '.style' - Qt style sheet for dialog
1192 - '.height', '.width', '.x', '.y' - dialog geometry
1193 - '.label' - dialog message (can contain basic HTML)
1194 - '.modal' - set to true to make the dialog modal (to avoid other CopyQ windows to get input focus)
1195 - '.onTop' - set to true for the dialog to stay above other windows
1196
1197 :returns: Value or values from accepted dialog or ``undefined`` if dialog
1198 was canceled.
1199
1200 .. code-block:: js
1201
1202 dialog(
1203 '.title', 'Command Finished',
1204 '.label', 'Command <b>successfully</b> finished.'
1205 )
1206
1207 Accepting a dialog containing only a question returns ``true``
1208 (rejecting/cancelling the dialog returns ``undefined``).
1209
1210 .. code-block:: js
1211
1212 const remove = dialog(
1213 '.title', 'Remove Items',
1214 '.label', 'Do you really want to remove all items?'
1215 )
1216 if (!remove)
1217 abort();
1218
1219 Other arguments are used to get user input.
1220
1221 .. code-block:: js
1222
1223 var amount = dialog('.title', 'Amount?', 'Enter Amount', 'n/a')
1224 var filePath = dialog('.title', 'File?', 'Choose File', new File('/home'))
1225
1226 If multiple inputs are required, object is returned.
1227
1228 .. code-block:: js
1229
1230 var result = dialog(
1231 'Enter Amount', 'n/a',
1232 'Choose File', new File(str(currentPath))
1233 )
1234 print('Amount: ' + result['Enter Amount'] + '\n')
1235 print('File: ' + result['Choose File'] + '\n')
1236
1237 A combo box with an editable custom text/value can be created by passing an
1238 array argument. The default text can be provided using ``.defaultChoice``
1239 (by default it's the first item).
1240
1241 .. code-block:: js
1242
1243 var text = dialog('.defaultChoice', '', 'Select', ['a', 'b', 'c'])
1244
1245 A combo box with non-editable text can be created by prefixing the label
1246 argument with ``.combo:``.
1247
1248 .. code-block:: js
1249
1250 var text = dialog('.combo:Select', ['a', 'b', 'c'])
1251
1252 An item list can be created by prefixing the label argument with ``.list:``.
1253
1254 .. code-block:: js
1255
1256 var items = ['a', 'b', 'c']
1257 var selected_index = dialog('.list:Select', items)
1258 if (selected_index !== undefined)
1259 print('Selected item: ' + items[selected_index])
1260
1261 Icon for custom dialog can be set from icon font, file path or theme.
1262 Icons from icon font can be copied from icon selection dialog in Command
1263 dialog or dialog for setting tab icon (in menu 'Tabs/Change Tab Icon').
1264
1265 .. code-block:: js
1266
1267 var search = dialog(
1268 '.title', 'Search',
1269 '.icon', 'search', // Set icon 'search' from theme.
1270 'Search', ''
1271 )
1272
1273 .. js:function:: menuItems(text...)
1274
1275 Opens menu with given items and returns selected item or an empty string.
1276
1277 :returns: Selected item or empty string if menu was canceled.
1278 :rtype: string
1279
1280 .. code-block:: js
1281
1282 var selectedText = menuItems('x', 'y', 'z')
1283 if (selectedText)
1284 popup('Selected', selectedText)
1285
1286 .. js:function:: /*items*/ menuItems(items[])
1287
1288 Opens menu with given items and returns index of selected item or -1.
1289
1290 Menu item label is taken from :js:data:`mimeText` format an icon is taken
1291 from :js:data:`mimeIcon` format.
1292
1293 :returns: Selected item index or `-1` if menu was canceled.
1294 :rtype: int
1295
1296 .. code-block:: js
1297
1298 var items = selectedItemsData()
1299 var selectedIndex = menuItems(items)
1300 if (selectedIndex != -1)
1301 popup('Selected', items[selectedIndex][mimeText])
1302
1303 .. js:function:: settings()
1304
1305 Returns array with names of all custom user options.
1306
1307 These options can be managed by various commands, much like cookies
1308 are used by web applications in a browser. A typical usage is to remember
1309 options lastly selected by user in a custom dialog displayed by a command.
1310
1311 These options are persisted within the ``[General]`` section of a corresponding
1312 ``copyq-scripts.ini`` file. But if an option is named like ``group/...``,
1313 then it is written to a section named ``[group]`` instead.
1314 By grouping options like this, we can avoid potential naming collisions
1315 with other commands.
1316
1317 :returns: Available custom options.
1318 :rtype: array of strings
1319
1320 .. js:function:: /*get*/ Value settings(optionName)
1321
1322 Returns value for a custom user option.
1323
1324 :returns: Current value of the custom options, ``undefined`` if the option
1325 was not set.
1326
1327 .. js:function:: /*set*/ settings(optionName, value)
1328
1329 Sets value for a new custom user option or overrides existing one.
1330
1331 .. js:function:: dateString(format)
1332
1333 Returns text representation of current date and time.
1334
1335 See `Date QML Type <https://doc.qt.io/qt-6/qdatetime.html#toString>`__ for
1336 details on formatting date and time.
1337
1338 :returns: Current date and time as string.
1339 :rtype: string
1340
1341 Example:
1342
1343 .. code-block:: js
1344
1345 var now = dateString('yyyy-MM-dd HH:mm:ss')
1346
1347 .. js:function:: commands()
1348
1349 Return list of all commands.
1350
1351 :returns: Array of all commands.
1352 :rtype: array of :js:class:`Command`
1353
1354 .. js:function:: setCommands(Command[])
1355
1356 Clear previous commands and set new ones.
1357
1358 To add new command:
1359
1360 .. code-block:: js
1361
1362 var cmds = commands()
1363 cmds.unshift({
1364 name: 'New Command',
1365 automatic: true,
1366 input: 'text/plain',
1367 cmd: 'copyq: popup("Clipboard", input())'
1368 })
1369 setCommands(cmds)
1370
1371 .. js:function:: Command[] importCommands(String)
1372
1373 Return list of commands from exported commands text.
1374
1375 :returns: Array of commands loaded from a file path.
1376 :rtype: array of :js:class:`Command`
1377
1378 .. js:function:: String exportCommands(Command[])
1379
1380 Return exported command text.
1381
1382 :returns: Serialized commands.
1383 :rtype: string
1384
1385 .. js:function:: addCommands(Command[])
1386
1387 Opens Command dialog, adds commands and waits for user to confirm the
1388 dialog.
1389
1390 .. js:function:: NetworkReply networkGet(url)
1391
1392 Sends HTTP GET request.
1393
1394 :returns: HTTP reply.
1395 :rtype: :js:class:`NetworkReply`
1396
1397 .. js:function:: NetworkReply networkPost(url, postData)
1398
1399 Sends HTTP POST request.
1400
1401 :returns: HTTP reply.
1402 :rtype: :js:class:`NetworkReply`
1403
1404 .. js:function:: NetworkReply networkGetAsync(url)
1405
1406 Same as :js:func:`networkGet` but the request is asynchronous.
1407
1408 The request is handled asynchronously and may not be finished until you get
1409 a property of the reply.
1410
1411 :returns: HTTP reply.
1412 :rtype: :js:class:`NetworkReply`
1413
1414 .. js:function:: NetworkReply networkPostAsync(url, postData)
1415
1416 Same as :js:func:`networkPost` but the request is asynchronous.
1417
1418 The request is handled asynchronously and may not be finished until you get
1419 a property of the reply.
1420
1421 :returns: HTTP reply.
1422 :rtype: :js:class:`NetworkReply`
1423
1424 .. js:function:: env(name)
1425
1426 Returns value of environment variable with given name.
1427
1428 :returns: Value of the environment variable.
1429 :rtype: :js:class:`ByteArray`
1430
1431 .. js:function:: setEnv(name, value)
1432
1433 Sets environment variable with given name to given value.
1434
1435 :returns: ``true`` if the variable was set, otherwise ``false``.
1436 :rtype: bool
1437
1438 .. js:function:: sleep(time)
1439
1440 Wait for given time in milliseconds.
1441
1442 .. js:function:: afterMilliseconds(time, function)
1443
1444 Executes function after given time in milliseconds.
1445
1446 .. js:function:: screenNames()
1447
1448 Returns list of available screen names.
1449
1450 :returns: Available screen names.
1451 :rtype: array of strings
1452
1453 .. js:function:: screenshot(format='png', [screenName])
1454
1455 Returns image data with screenshot.
1456
1457 Default ``screenName`` is name of the screen with mouse cursor.
1458
1459 You can list valid values for ``screenName`` with :js:func:`screenNames`.
1460
1461 :returns: Image data.
1462 :rtype: :js:class:`ByteArray`
1463
1464 Example:
1465
1466 .. code-block:: js
1467
1468 copy('image/png', screenshot())
1469
1470 .. js:function:: screenshotSelect(format='png', [screenName])
1471
1472 Same as :js:func:`screenshot` but allows to select an area on screen.
1473
1474 :returns: Image data.
1475 :rtype: :js:class:`ByteArray`
1476
1477 .. js:function:: queryKeyboardModifiers()
1478
1479 Returns list of currently pressed keyboard modifiers which can be 'Ctrl',
1480 'Shift', 'Alt', 'Meta'.
1481
1482 :returns: Currently pressed keyboard modifiers.
1483 :rtype: array of strings
1484
1485 .. js:function:: pointerPosition()
1486
1487 Returns current mouse pointer position (x, y coordinates on screen).
1488
1489 :returns: Current mouse pointer coordinates.
1490 :rtype: array of ints (with two elements)
1491
1492 .. js:function:: setPointerPosition(x, y)
1493
1494 Moves mouse pointer to given coordinates on screen.
1495
1496 :throws Error: Thrown if the pointer position couldn't be set (for example,
1497 unsupported on current the system).
1498
1499 .. js:function:: iconColor()
1500
1501 Get current tray and window icon color name.
1502
1503 :returns: Current icon color.
1504 :rtype: string
1505
1506 .. js:function:: /*set*/ iconColor(colorName)
1507
1508 Set current tray and window icon color name (examples: 'orange', '#ffa500', '#09f').
1509
1510 Resets color if color name is empty string.
1511
1512 :throws Error: Thrown if the color name is empty or invalid.
1513
1514 .. code-block:: js
1515
1516 // Flash icon for few moments to get attention.
1517 var color = iconColor()
1518 for (var i = 0; i < 10; ++i) {
1519 iconColor("red")
1520 sleep(500)
1521 iconColor(color)
1522 sleep(500)
1523 }
1524
1525 .. seealso::
1526
1527 :js:data:`mimeColor`
1528
1529 .. js:function:: iconTag()
1530
1531 Get current tray and window icon tag text.
1532
1533 :returns: Current icon tag.
1534 :rtype: string
1535
1536 .. js:function:: /*set*/ iconTag(tag)
1537
1538 Set current tray and window tag text.
1539
1540 .. js:function:: iconTagColor()
1541
1542 Get current tray and window tag color name.
1543
1544 :returns: Current icon tag color.
1545 :rtype: string
1546
1547 .. js:function:: /*set*/ iconTagColor(colorName)
1548
1549 Set current tray and window tag color name.
1550
1551 :throws Error: Thrown if the color name is invalid.
1552
1553 .. js:function:: loadTheme(path)
1554
1555 Loads theme from an INI file.
1556
1557 :throws Error: Thrown if the file cannot be read or is not valid INI format.
1558
1559 .. js:function:: onClipboardChanged()
1560
1561 Called when clipboard or `primary selection`_ changes and is not set by
1562 CopyQ, is not marked as hidden nor secret (see the other callbacks).
1563
1564 Default implementation is:
1565
1566 .. code-block:: js
1567
1568 if (!hasData()) {
1569 updateClipboardData();
1570 } else if (runAutomaticCommands()) {
1571 saveData();
1572 updateClipboardData();
1573 } else {
1574 clearClipboardData();
1575 }
1576
1577 .. js:function:: onOwnClipboardChanged()
1578
1579 Called when clipboard or `primary selection`_ is set by CopyQ and is not
1580 marked as hidden nor secret (see the other callbacks).
1581
1582 Owned clipboard data contains :js:data:`mimeOwner` format.
1583
1584 Default implementation calls :js:func:`updateClipboardData`.
1585
1586 .. js:function:: onHiddenClipboardChanged()
1587
1588 Called when clipboard or `primary selection`_ changes and is marked as
1589 hidden but not secret (see the other callbacks).
1590
1591 Hidden clipboard data contains :js:data:`mimeHidden` format set to ``1``.
1592
1593 Default implementation calls :js:func:`updateClipboardData`.
1594
1595 .. js:function:: onSecretClipboardChanged()
1596
1597 Called if the clipboard or `primary selection`_ changes and contains a
1598 password or other secret (for example, copied from clipboard manager).
1599
1600 The default implementation clears all data, so they are not accessible using
1601 :js:func:`data` and :js:func:`dataFormats`, except :js:data:`mimeSecret`,
1602 and calls :js:func:`updateClipboardData`.
1603
1604 **Be careful overriding** this function (via a Script command). Calling
1605 `onClipboardChanged()` without clearing the data and without any further
1606 checks can cause storing and processing secrets from password managers. On
1607 the other hand, it can help to get access to the data copied, for example
1608 from a web browser in private mode.
1609
1610 .. js:function:: onClipboardUnchanged()
1611
1612 Called when clipboard or `primary selection`_ changes but data remained the same.
1613
1614 Default implementation does nothing.
1615
1616 .. js:function:: onStart()
1617
1618 Called when application starts.
1619
1620 .. js:function:: onExit()
1621
1622 Called just before application exists.
1623
1624 .. js:function:: runAutomaticCommands()
1625
1626 Executes automatic commands on current data.
1627
1628 If an executed command calls :js:func:`ignore` or have "Remove Item" or
1629 "Transform" check box enabled, following automatic commands won't be
1630 executed and the function returns ``false``. Otherwise ``true`` is returned.
1631
1632 :returns: ``true`` if clipboard data should be stored, otherwise ``false``.
1633 :rtype: bool
1634
1635 .. js:function:: clearClipboardData()
1636
1637 Clear clipboard visibility in GUI.
1638
1639 Default implementation is:
1640
1641 .. code-block:: js
1642
1643 if (isClipboard()) {
1644 setTitle();
1645 hideDataNotification();
1646 }
1647
1648 .. js:function:: updateTitle()
1649
1650 Update main window title and tool tip from current data.
1651
1652 Called when clipboard changes.
1653
1654 .. js:function:: updateClipboardData()
1655
1656 Sets current clipboard data for tray menu, window title and notification.
1657
1658 Default implementation is:
1659
1660 .. code-block:: js
1661
1662 if (isClipboard()) {
1663 updateTitle();
1664 showDataNotification();
1665 setClipboardData();
1666 }
1667
1668 .. js:function:: setTitle([title])
1669
1670 Set main window title and tool tip.
1671
1672 .. js:function:: synchronizeToSelection(text)
1673
1674 Synchronize current data from clipboard to `primary selection`_.
1675
1676 Called automatically from clipboard monitor process if option
1677 ``copy_clipboard`` is enabled.
1678
1679 Default implementation calls :js:func:`provideSelection`.
1680
1681 .. js:function:: synchronizeFromSelection(text)
1682
1683 Synchronize current data from `primary selection`_ to clipboard.
1684
1685 Called automatically from clipboard monitor process if option
1686 ``copy_selection`` is enabled.
1687
1688 Default implementation calls :js:func:`provideClipboard`.
1689
1690 .. js:function:: provideClipboard()
1691
1692 Starts a process provides a data for clipboard.
1693
1694 The data can be set using :js:func:`setData`.
1695
1696 The script must be started with ``--clipboard-access`` command line flag.
1697
1698 .. js:function:: provideSelection()
1699
1700 Starts a process that provides a data for `primary selection`_.
1701
1702 The data can be set using :js:func:`setData`.
1703
1704 The script must be started with ``--clipboard-access`` command line flag.
1705
1706 .. js:function:: monitorClipboard()
1707
1708 Starts a clipboard monitor process.
1709
1710 The script must be started with ``--clipboard-access`` command line flag.
1711
1712 .. js:function:: clipboardFormatsToSave()
1713
1714 Returns list of clipboard format to save automatically.
1715
1716 :returns: Formats to get and save automatically from clipboard.
1717 :rtype: array of strings
1718
1719 Override the function, for example, to save only plain text:
1720
1721 .. code-block:: js
1722
1723 global.clipboardFormatsToSave = function() {
1724 return ["text/plain"]
1725 }
1726
1727 Or to save additional formats:
1728
1729 .. code-block:: js
1730
1731 var originalFunction = global.clipboardFormatsToSave;
1732 global.clipboardFormatsToSave = function() {
1733 return originalFunction().concat([
1734 "text/uri-list",
1735 "text/xml"
1736 ])
1737 }
1738
1739 .. js:function:: saveData()
1740
1741 Save current data (depends on `mimeOutputTab`).
1742
1743 .. js:function:: hasData()
1744
1745 Returns true only if some non-empty data can be returned by data().
1746
1747 Empty data is combination of whitespace and null characters or some internal
1748 formats (`mimeWindowTitle`, `mimeClipboardMode` etc.)
1749
1750 :returns: ``true`` if there are some data, otherwise ``false``.
1751 :rtype: bool
1752
1753 .. js:function:: showDataNotification()
1754
1755 Show notification for current data.
1756
1757 .. js:function:: hideDataNotification()
1758
1759 Hide notification for current data.
1760
1761 .. js:function:: setClipboardData()
1762
1763 Sets clipboard data for menu commands.
1764
1765 .. js:function:: styles()
1766
1767 List available styles for ``style`` option.
1768
1769 :returns: Style identifiers.
1770 :rtype: array of strings
1771
1772 To change or update style use:
1773
1774 .. code-block:: js
1775
1776 config("style", styleName)
1777
1778 .. js:function:: stats()
1779
1780 Get runtime diagnostics and statistics about the application state.
1781
1782 Reports QObject tree class/name counts, clipboard model row counts
1783 and data sizes, item data directory size on disk, tab load state,
1784 running actions, command counts by type, loaded plugins with
1785 enabled/disabled state, log file sizes, and process memory usage.
1786
1787 :returns: Multi-line string with statistics including:
1788 ``#ObjectName: COUNT`` for QObject instances with object name,
1789 ``/Path/To#The/#Object: COUNT`` for QObject instances with specific path,
1790 ``TYPE: COUNT`` for QObject instances of specific type/class,
1791 ``MODEL path: rows=N, dataSize=B (human)`` for item models,
1792 ``DATA_DIR path: size=B (human)`` for the item data directory,
1793 ``TABS: total=N, loaded=N`` for tab load state,
1794 ``ACTION description | pid=P rss=B (human), ...`` for each running action with per-sub-process memory,
1795 ``COMMANDS: automatic=N, display=N, menu=N, tray_menu=N, script=N`` for command counts,
1796 ``PLUGIN id: enabled/disabled`` for each loaded plugin,
1797 ``LOG_FILES: count=N, size=B (human)`` for log file total size,
1798 ``MEMORY: rss=B (human)`` for process resident memory (platform-dependent).
1799 :rtype: string
1800
1801 .. js:function:: onItemsAdded()
1802
1803 Called when items are added to a tab.
1804
1805 The target tab is returned by `selectedTab()`.
1806
1807 The new items can be accessed with `selectedItemsData()`,
1808 `selectedItemData()`, `selectedItems()` and `ItemSelection().current()`.
1809
1810 .. js:function:: onItemsRemoved()
1811
1812 Called when items are being removed from a tab.
1813
1814 The target tab is returned by `selectedTab()`.
1815
1816 The items scheduled for removal can be accessed with `selectedItemsData()`,
1817 `selectedItemData()`, `selectedItems()` and `ItemSelection().current()`.
1818
1819 If the exit code is non-zero (for example `fail()` is called), items will
1820 not be removed. But this can also cause a new items not to be added if the
1821 tab is full.
1822
1823 .. js:function:: onItemsChanged()
1824
1825 Called when data in items change.
1826
1827 The target tab is returned by `selectedTab()`.
1828
1829 The modified items can be accessed with `selectedItemsData()`,
1830 `selectedItemData()`, `selectedItems()` and `ItemSelection().current()`.
1831
1832 .. js:function:: onTabSelected()
1833
1834 Called when another tab is opened.
1835
1836 The newly selected tab is returned by `selectedTab()`.
1837
1838 The changed items can be accessed with `selectedItemsData()`,
1839 `selectedItemData()`, `selectedItems()` and `ItemSelection().current()`.
1840
1841 .. js:function:: onItemsLoaded()
1842
1843 Called when all items are loaded into a tab.
1844
1845 The target tab is returned by `selectedTab()`.
1846
1847 Types
1848 -----
1849
1850 .. js:class:: ByteArray
1851
1852 Wrapper for QByteArray Qt class.
1853
1854 See `QByteArray <http://doc.qt.io/qt-6/qbytearray.html>`__.
1855
1856 ``ByteArray`` is used to store all item data (image data, HTML and even
1857 plain text).
1858
1859 Use :js:func:`str` to convert it to string. Strings are usually more
1860 versatile. For example to concatenate two items, the data need to be
1861 converted to strings first.
1862
1863 .. code-block:: js
1864
1865 var text = str(read(0)) + str(read(1))
1866
1867 .. js:class:: File
1868
1869 Wrapper for QFile Qt class.
1870
1871 See `QFile <http://doc.qt.io/qt-6/qfile.html>`__.
1872
1873 To open file in different modes use:
1874
1875 - `open()` - read/write
1876 - `openReadOnly()` - read only
1877 - `openWriteOnly()` - write only, truncates the file
1878 - `openAppend()` - write only, appends to the file
1879
1880 Following code reads contents of "README.md" file from current
1881 directory:
1882
1883 .. code-block:: js
1884
1885 var f = new File('README.md')
1886 if (!f.openReadOnly())
1887 throw 'Failed to open the file: ' + f.errorString()
1888 var bytes = f.readAll()
1889
1890 Following code writes to a file in home directory:
1891
1892 .. code-block:: js
1893
1894 var dataToWrite = 'Hello, World!'
1895 var filePath = Dir().homePath() + '/copyq.txt'
1896 var f = new File(filePath)
1897 if (!f.openWriteOnly() || f.write(dataToWrite) == -1)
1898 throw 'Failed to save the file: ' + f.errorString()
1899
1900 // Always flush the data and close the file,
1901 // before opening the file in other application.
1902 f.close()
1903
1904 .. js:class:: Dir
1905
1906 Wrapper for QDir Qt class.
1907
1908 Use forward slash as path separator, for example "D:/Documents/".
1909
1910 See `QDir <http://doc.qt.io/qt-6/qdir.html>`__.
1911
1912 .. js:class:: TemporaryFile
1913
1914 Wrapper for QTemporaryFile Qt class.
1915
1916 See `QTemporaryFile <https://doc.qt.io/qt-6/qtemporaryfile.html>`__.
1917
1918 .. code-block:: js
1919
1920 var f = new TemporaryFile()
1921 f.open()
1922 f.setAutoRemove(false)
1923 popup('New temporary file', f.fileName())
1924
1925 To open file in different modes, use same open methods as for `File`.
1926
1927 .. js:class:: Settings
1928
1929 Reads and writes INI configuration files. Wrapper for QSettings Qt class.
1930
1931 See `QSettings <https://doc.qt.io/qt-6/qsettings.html>`__.
1932
1933 .. code-block:: js
1934
1935 // Open INI file
1936 var configPath = Dir().homePath() + '/copyq.ini'
1937 var settings = new Settings(configPath)
1938
1939 // Save an option
1940 settings.setValue('option1', 'test')
1941
1942 // Store changes to the config file now instead of at the end of
1943 // executing the script
1944 settings.sync()
1945
1946 // Read the option value
1947 var value = settings.value('option1')
1948
1949 Working with arrays:
1950
1951 .. code-block:: js
1952
1953 // Write array
1954 var settings = new Settings(configPath)
1955 settings.beginWriteArray('array1')
1956 settings.setArrayIndex(0)
1957 settings.setValue('some_option', 1)
1958 settings.setArrayIndex(1)
1959 settings.setValue('some_option', 2)
1960 settings.endArray()
1961 settings.sync()
1962
1963 // Read array
1964 var settings = new Settings(configPath)
1965 const arraySize = settings.beginReadArray('array1')
1966 for (var i = 0; i < arraySize; i++) {
1967 settings.setArrayIndex(i);
1968 print('Index ' + i + ': ' + settings.value('some_option') + '\n')
1969 }
1970
1971 .. js:class:: Item
1972
1973 Object with MIME types of an item.
1974
1975 Each property is MIME type with data.
1976
1977 Example:
1978
1979 .. code-block:: js
1980
1981 var item = {}
1982 item[mimeText] = 'Hello, World!'
1983 item[mimeHtml] = '<p>Hello, World!</p>'
1984 write(mimeItems, pack(item))
1985
1986 .. js:class:: ItemSelection
1987
1988 List of items from given tab.
1989
1990 An item in the list represents the same item in tab even if it is moved to a
1991 different row.
1992
1993 New items in the tab are not added automatically into the selection.
1994
1995 To create new empty selection use ``ItemSelection()`` then add items with
1996 ``select*()`` methods.
1997
1998 Example - move matching items to the top of the tab:
1999
2000 .. code-block:: js
2001
2002 ItemSelection().select(/^prefix/).move(0)
2003
2004 Example - remove all items from given tab but keep pinned items:
2005
2006 .. code-block:: js
2007
2008 ItemSelection(tabName).selectRemovable().removeAll();
2009
2010 Example - modify items containing "needle" text:
2011
2012 .. code-block:: js
2013
2014 var sel = ItemSelection().select(/needle/, mimeText);
2015 for (var index = 0; index < sel.length; ++index) {
2016 var item = sel.itemAtIndex(index);
2017 item[mimeItemNotes] = 'Contains needle';
2018 sel.setItemAtIndex(index, item);
2019 }
2020
2021 Example - selection with new items only:
2022
2023 .. code-block:: js
2024
2025 var sel = ItemSelection().selectAll()
2026 add("New Item 1")
2027 add("New Item 2")
2028 sel.invert()
2029 sel.items();
2030
2031 Example - sort items alphabetically:
2032
2033 .. code-block:: js
2034
2035 var sel = ItemSelection().selectAll();
2036 const texts = sel.itemsFormat(mimeText);
2037 sel.sort(function(i,j){
2038 return texts[i] < texts[j];
2039 });
2040
2041 .. js:attribute:: tab
2042
2043 Tab name
2044
2045 .. js:attribute:: length
2046
2047 Number of filtered items in the selection
2048
2049 .. js:method:: selectAll()
2050
2051 Select all items in the tab.
2052
2053 :returns: self
2054 :rtype: ItemSelection
2055
2056 .. js:method:: select(regexp, [mimeType])
2057
2058 Select additional items matching the regular expression.
2059
2060 If regexp is a valid regular expression and ``mimeType`` is not set,
2061 this selects items with matching text.
2062
2063 If regexp matches empty strings and ``mimeType`` is set, this selects
2064 items containing the MIME type.
2065
2066 If regexp is ``undefined`` and ``mimeType`` is set, this select items
2067 not containing the MIME type.
2068
2069 :returns: self
2070 :rtype: ItemSelection
2071
2072 .. js:method:: selectRemovable()
2073
2074 Select only items that can be removed.
2075
2076 :returns: self
2077 :rtype: ItemSelection
2078
2079 .. js:method:: invert()
2080
2081 Select only items not in the selection.
2082
2083 :returns: self
2084 :rtype: ItemSelection
2085
2086 .. js:method:: deselectIndexes(int[])
2087
2088 Deselect items at given indexes in the selection.
2089
2090 :returns: self
2091 :rtype: ItemSelection
2092
2093 .. js:method:: deselectSelection(ItemSelection)
2094
2095 Deselect items in other selection.
2096
2097 :returns: self
2098 :rtype: ItemSelection
2099
2100 .. js:method:: current()
2101
2102 Deselects all and selects only the items which were selected when the
2103 command was triggered.
2104
2105 See `Selected Items`_.
2106
2107 :returns: self
2108 :rtype: ItemSelection
2109
2110 .. js:method:: removeAll()
2111
2112 Delete all items in the selection (if possible).
2113
2114 :returns: self
2115 :rtype: ItemSelection
2116
2117 .. js:method:: move(row)
2118
2119 Move all items in the selection to the target row.
2120
2121 :returns: self
2122 :rtype: ItemSelection
2123
2124 .. js:method:: sort(comparisonFunction)
2125
2126 Sort items with a comparison function.
2127
2128 The comparison function takes two arguments, indexes to the selection,
2129 and returns true only if the item in the selection under the first index
2130 should be sorted above the item under the second index.
2131
2132 Items will be reordered in the tab and in the selection object.
2133
2134 :returns: self
2135 :rtype: ItemSelection
2136
2137 .. js:method:: copy()
2138
2139 Clone the selection object.
2140
2141 :returns: cloned object
2142 :rtype: ItemSelection
2143
2144 .. js:method:: rows()
2145
2146 Returns selected rows.
2147
2148 :returns: Selected rows
2149 :rtype: array of ints
2150
2151 .. js:method:: itemAtIndex(index)
2152
2153 Returns item data at given index in the selection.
2154
2155 :returns: Item data
2156 :rtype: :js:class:`Item`
2157
2158 .. js:method:: setItemAtIndex(index, Item)
2159
2160 Sets data to the item at given index in the selection.
2161
2162 :returns: self
2163 :rtype: ItemSelection
2164
2165 .. js:method:: items()
2166
2167 Return list of data from selected items.
2168
2169 :returns: Selected item data
2170 :rtype: array of :js:class:`Item`
2171
2172 .. js:method:: setItems(Item[])
2173
2174 Set data for selected items.
2175
2176 :returns: self
2177 :rtype: ItemSelection
2178
2179 .. js:method:: itemsFormat(mimeType)
2180
2181 Return list of data from selected items containing specified MIME type.
2182
2183 :returns: Selected item data containing only the format
2184 :rtype: array of :js:class:`Item`
2185
2186 .. js:method:: setItemsFormat(mimeType, data)
2187
2188 Set data for given MIME type for the selected items.
2189
2190 :returns: self
2191 :rtype: ItemSelection
2192
2193 .. js:class:: FinishedCommand
2194
2195 Properties of finished command.
2196
2197 .. js:attribute:: stdout
2198
2199 Standard output
2200
2201 .. js:attribute:: stderr
2202
2203 Standard error output
2204
2205 .. js:attribute:: exit_code
2206
2207 Exit code
2208
2209 .. js:class:: NetworkRequest
2210
2211 Make HTTP requests.
2212
2213 Example:
2214
2215 .. code-block:: js
2216
2217 let req = NetworkRequest();
2218
2219 // allow redirects
2220 req.maxRedirects = 5;
2221
2222 // set request headers
2223 req.headers = {
2224 'User-Agent': req.headers['User-Agent'],
2225 'Accept': 'application/json',
2226 };
2227
2228 // create JSON data
2229 const data = JSON.stringify({text: 'Hello, **world**!'});
2230
2231 // send POST request
2232 const reply = req.request(
2233 'POST', 'https://api.github.com/markdown', data)
2234
2235 // the request is synchronous and may not be finished
2236 // until a property is called (like reply.data or reply.status)
2237 if (!reply.finished) { serverLog('Processing...'); }
2238 print(reply.data);
2239
2240 .. js:attribute:: headers
2241
2242 Object with HTTP headers
2243
2244 .. js:attribute:: maxRedirects
2245
2246 Maximum number of redirects to follow (default is 0)
2247
2248 .. js:class:: NetworkReply
2249
2250 Received network reply object.
2251
2252 .. js:attribute:: data
2253
2254 Reply data
2255
2256 .. js:attribute:: status
2257
2258 HTTP status
2259
2260 .. js:attribute:: error``
2261
2262 Error string (set only if an error occurred)
2263
2264 .. js:attribute:: redirect
2265
2266 URL for redirection (set only if redirection is needed)
2267
2268 .. js:attribute:: headers
2269
2270 Reply headers (array of pairs with header name and header content)
2271
2272 .. js:attribute:: finished
2273
2274 True only if request has been completed, false only for unfinished
2275 asynchronous requests
2276
2277 .. js:attribute:: url
2278
2279 URL of the final request (may be different from the original if
2280 redirects are enabled)
2281
2282 .. js:class:: Command
2283
2284 Wrapper for a command (from Command dialog).
2285
2286 Properties are same as members of `Command
2287 struct <https://github.com/hluk/CopyQ/blob/master/src/common/command.h>`__.
2288
2289 Objects
2290 -------
2291
2292 .. js:data:: arguments (Array)
2293
2294 Array for accessing arguments passed to current function or the script
2295 (``arguments[0]`` is the script itself).
2296
2297 .. js:data:: global
2298
2299 Object allowing to modify global scope which contains all functions like
2300 :js:func:`copy` or :js:func:`add`.
2301
2302 This is useful for :ref:`commands-script`.
2303
2304 .. js:data:: console
2305
2306 Allows some logging and debugging.
2307
2308 .. code-block:: js
2309
2310 // Print a message if COPYQ_LOG_LEVEL=DEBUG
2311 // environment variable is set
2312 console.log(
2313 'Supported console properties/functions:',
2314 Object.getOwnPropertyNames(console))
2315 console.warn('Changing clipboard...')
2316
2317 // Elapsed time
2318 console.time('copy')
2319 copy('TEST')
2320 console.timeEnd('copy')
2321
2322 // Ensure a condition is true before continuing
2323 console.assert(str(clipboard()) == 'TEST')
2324
2325 MIME Types
2326 ----------
2327
2328 Item and clipboard can provide multiple formats for their data. Type of
2329 the data is determined by MIME type.
2330
2331 Here is list of some common and builtin (start with
2332 ``application/x-copyq-``) MIME types.
2333
2334 These MIME types values are assigned to global variables prefixed with
2335 ``mime``.
2336
2337 .. note::
2338
2339 Content for following types is UTF-8 encoded.
2340
2341 .. js:data:: mimeText
2342
2343 Data contains plain text content. Value: 'text/plain'.
2344
2345 .. js:data:: mimeHtml
2346
2347 Data contains HTML content. Value: 'text/html'.
2348
2349 .. js:data:: mimeUriList
2350
2351 Data contains list of links to files, web pages etc. Value: 'text/uri-list'.
2352
2353 .. js:data:: mimeWindowTitle
2354
2355 Current window title for copied clipboard. Value: 'application/x-copyq-owner-window-title'.
2356
2357 .. js:data:: mimeItems
2358
2359 Serialized items. Value: 'application/x-copyq-item'.
2360
2361 .. js:data:: mimeItemNotes
2362
2363 Data contains notes for item. Value: 'application/x-copyq-item-notes'.
2364
2365 .. js:data:: mimeIcon
2366
2367 Data contains icon for item. Value: 'application/x-copyq-item-icon'.
2368
2369 .. js:data:: mimeOwner
2370
2371 If available, the clipboard was set from CopyQ (from script or copied items). Value: 'application/x-copyq-owner'.
2372
2373 Such clipboard is ignored in CopyQ, i.e. it won't be stored in clipboard
2374 tab and automatic commands won't be executed on it.
2375
2376 .. js:data:: mimeClipboardMode
2377
2378 Contains ``selection`` if data is from `primary selection`_. Value: 'application/x-copyq-clipboard-mode'.
2379
2380 .. js:data:: mimeCurrentTab
2381
2382 Current tab name when invoking command from main window. Value: 'application/x-copyq-current-tab'.
2383
2384 Following command print the tab name when invoked from main window:
2385
2386 ::
2387
2388 copyq data application/x-copyq-current-tab
2389 copyq selectedTab
2390
2391 .. js:data:: mimeSelectedItems
2392
2393 Selected items when invoking command from main window. Value: 'application/x-copyq-selected-items'.
2394
2395 .. js:data:: mimeCurrentItem
2396
2397 Current item when invoking command from main window. Value: 'application/x-copyq-current-item'.
2398
2399 .. js:data:: mimeHidden
2400
2401 If set to ``1``, the clipboard or item content will be hidden in GUI. Value: 'application/x-copyq-hidden'.
2402
2403 This won't hide notes and tags.
2404
2405 Example -- clear window title and tool tip:
2406
2407 ::
2408
2409 copyq copy application/x-copyq-hidden 1 plain/text "This is secret"
2410
2411 .. js:data:: mimeSecret
2412
2413 If set to ``1``, the clipboard contains a password or other secret (for example, copied from clipboard manager).
2414
2415 .. js:data:: mimeShortcut
2416
2417 Application or global shortcut which activated the command. Value: 'application/x-copyq-shortcut'.
2418
2419 ::
2420
2421 copyq:
2422 var shortcut = data(mimeShortcut)
2423 popup("Shortcut Pressed", shortcut)
2424
2425 .. js:data:: mimeColor
2426
2427 Item color (same as the one used by themes). Value: 'application/x-copyq-color'.
2428
2429 Examples::
2430
2431 #ffff00
2432 rgba(255,255,0,0.5)
2433 bg - #000099
2434
2435 .. js:data:: mimeOutputTab
2436
2437 Name of the tab where to store new item. Value: 'application/x-copyq-output-tab'.
2438
2439 The clipboard data will be stored in tab with this name after all
2440 automatic commands are run.
2441
2442 Clear or remove the format to omit storing the data.
2443
2444 Example -- automatic command that avoids storing clipboard data:
2445
2446 .. code-block:: js
2447
2448 removeData(mimeOutputTab)
2449
2450 Valid only in automatic commands.
2451
2452 .. js:data:: mimeDisplayItemInMenu
2453
2454 Indicates if display commands run for a menu. Value: 'application/x-copyq-display-item-in-menu'.
2455
2456 Set to "1" for display commands if the item data is related to a menu item
2457 instead of an item list.
2458
2459 Selected Items
2460 --------------
2461
2462 The internal state for currently evaluated script/command stores references
2463 (not rows or item data) to the current and selected items and it do not change
2464 after the state is retrieved from GUI.
2465
2466 The state is retrieved before the script/command starts if it is invoked from
2467 the application with a shortcut, from menu, toolbar or the Action dialog.
2468 Otherwise, the state is retrieved when needed (for example the first
2469 ``selectedItems()`` call) for scripts/commands run externally (for example from
2470 command line or from automatic commands on clipboard content change).
2471
2472 If a selected or current item is moved, script functions will return the new
2473 rows. For example ``selectedItems()`` returning ``[0,1]`` will return ``[1,0]``
2474 after the items are swapped. Same goes for selected item data.
2475
2476 If a selected or current item is removed, their references in the internal
2477 state are invalidated. These references will return -1 for row and empty object
2478 for item data. For example ``selectedItems()`` returning ``[0,1]`` will return
2479 ``[0,-1]`` after the item on the second row is removed.
2480
2481 If tab is renamed, all references to current and selected items are invalidated
2482 because the tab data need to be initiated again.
2483
2484 Primary Selection
2485 -----------------
2486
2487 On many Linux and BSD desktop environments, selecting text with the mouse
2488 places it in the *primary selection*, which can be pasted with a middle mouse
2489 button click. This is separate from the regular clipboard used by copy/paste
2490 shortcuts.
2491
2492 CopyQ supports reading and writing the primary selection on platforms that
2493 provide it (X11 and Wayland). On Wayland, support depends on the compositor
2494 and the `KGuiAddons <https://invent.kde.org/frameworks/kguiaddons>`_ library;
2495 notably, GNOME does not support it natively, but CopyQ 14.0.0 and later work
2496 around this via the bundled *CopyQ Clipboard Monitor* GNOME extension.
2497
2498 On unsupported platforms, functions that use the primary selection do nothing
2499 (for example :js:func:`copySelection`) or return ``undefined`` (in case of
2500 :js:func:`selection`).
2501
2502 CopyQ can synchronize the clipboard with the primary selection. This can be
2503 enabled in Preferences on the General tab under *Clipboard Manipulation*, or
2504 from the command line:
2505
2506 .. code-block:: js
2507
2508 config('copy_clipboard', 'true') // clipboard to primary selection
2509 config('copy_selection', 'true') // primary selection to clipboard
2510
2511 For synchronization, CopyQ runs a helper process (for example
2512 ``copyq --clipboard-access synchronizeToSelection``). Running helpers can be
2513 inspected from *File — Process Manager*.
2514
2515 Custom automatic commands run on primary selection changes by default. This
2516 can be disabled in the *Clipboard Manipulation* section or from the command
2517 line:
2518
2519 .. code-block:: js
2520
2521 config('run_selection', 'false')
2522
2523 CopyQ can also store primary selection data automatically. Enable it in the
2524 *Clipboard Manipulation* section or from the command line:
2525
2526 .. code-block:: js
2527
2528 config('check_selection', 'true')
2529
2530 See also:
2531
2532 - `QClipboard — Notes for X11 Users <https://doc.qt.io/qt-6/qclipboard.html#notes-for-x11-users>`_
2533 - `freedesktop.org Clipboards Wiki <https://www.freedesktop.org/wiki/Specifications/ClipboardsWiki/>`_
2534
2535 Plugins
2536 -------
2537
2538 Use ``plugins`` object to access functionality of plugins.
2539
2540 .. js:function:: plugins.itemsync.selectedTabPath()
2541
2542 Returns synchronization path for current tab (mimeCurrentTab).
2543
2544 .. code-block:: js
2545
2546 var path = plugins.itemsync.selectedTabPath()
2547 var baseName = str(data(plugins.itemsync.mimeBaseName))
2548 var absoluteFilePath = Dir(path).absoluteFilePath(baseName)
2549 // NOTE: Known file suffix/extension can be missing in the full path.
2550
2551 .. js:class:: plugins.itemsync.tabPaths
2552
2553 Object that maps tab name to synchronization path.
2554
2555 .. code-block:: js
2556
2557 var tabName = 'Downloads'
2558 var path = plugins.itemsync.tabPaths[tabName]
2559
2560 .. js:data:: plugins.itemsync.mimeBaseName (application/x-copyq-itemsync-basename)
2561
2562 MIME type for accessing base name (without full path).
2563
2564 Known file suffix/extension can be missing in the base name.
2565
2566 .. js:data:: plugins.itemtags.userTags (Array)
2567
2568 List of user-defined tags.
2569
2570 .. js:function:: plugins.itemtags.tags(row, ...)
2571
2572 List of tags for items in given rows.
2573
2574 .. js:function:: plugins.itemtags.tag(tagName, [rows, ...])
2575
2576 Add given tag to items in given rows or selected items.
2577
2578 See `Selected Items`_.
2579
2580 .. js:function:: plugins.itemtags.untag(tagName, [rows, ...])
2581
2582 Remove given tag from items in given rows or selected items.
2583
2584 See `Selected Items`_.
2585
2586 .. js:function:: plugins.itemtags.clearTags([rows, ...])
2587
2588 Remove all tags from items in given rows or selected items.
2589
2590 See `Selected Items`_.
2591
2592 .. js:function:: plugins.itemtags.hasTag(tagName, [rows, ...])
2593
2594 Return true if given tag is present in any of items in given rows or
2595 selected items.
2596
2597 See `Selected Items`_.
2598
2599 .. js:data:: plugins.itemtags.mimeTags (application/x-copyq-tags)
2600
2601 MIME type for accessing list of tags.
2602
2603 Tags are separated by comma.
2604
2605 .. js:function:: plugins.itempinned.isPinned(rows, ...)
2606
2607 Returns true only if any item in given rows is pinned.
2608
2609 .. js:function:: plugins.itempinned.pin(rows, ...)
2610
2611 Pin items in given rows or selected items or new item created from clipboard
2612 (if called from automatic command).
2613
2614 .. js:function:: plugins.itempinned.unpin(rows, ...)
2615
2616 Unpin items in given rows or selected items.
2617
2618 .. js:data:: plugins.itempinned.mimePinned (application/x-copyq-item-pinned)
2619
2620 Presence of the format in an item indicates that it is pinned.