クリップボードマネージャCopyQの日本語の情報を補完するものです。

×

カスタムメニュー項目、グローバルショートカットを作成し、CopyQで新しいクリップボードコンテンツを自動的に処理するための便利なコマンドをいくつか紹介します。
以下のいずれかのコマンドを使用する場合は、それをクリップボードにコピーし、コマンドダイアログ(F6ショートカットで開く)のコマンドリストに貼り付けます。詳細については、共有コマンドをロードして共有する方法を参照してください。
これらのコマンドは、CopyQコマンドリポジトリで利用できます。

選択アイテムを連結

選択アイテムの連結テキストを含む新しいアイテムを作成します。
(ショートカットキー:スペース)
 [Command]
 Name=Join Selected Items
 Command=copyq add -- %1
 InMenu=true
 Icon=\xf066
 Shortcut=Space

現在の日時を貼り付け

現在の日付/時刻のテキストをクリップボードにコピーし、現在のウィンドウのカーソル部に貼り付けます。
(ショートカットキー:Win + Alt + T)
 [Command]
 Command="
     copyq:
     var time = dateString('yyyy-MM-dd hh:mm:ss')
     copy('現在の日時:' + time)
     paste()"
 GlobalShortcut=meta+alt+t
 Icon=\xf017
 Name=Paste Current Time

コピー時に音楽再生

クリップボードにコピーされるたび、オーディオファイル(例:copy.wav)を再生します。

Windowsの場合:
 [Command]
 Name=Play Sound on Copy
 Command="
     powershell:
     (New-Object Media.SoundPlayer \"C:\\Users\\copy.wav\").PlaySync()"
 Automatic=true
 Icon=\xf028
waveの代わりにBeep (440Hz,2秒間)とする場合
 [Console]::Beep(440,2000)
Linuxの場合 (VLC multimedia playerが必要):
 [Command]
 Name=Play Sound on Copy
 Command="
     bash:
     cvlc --play-and-exit ~/audio/example.mp3"
 Automatic=true
 Icon=\xf028

編集して貼付け

貼り付ける前に現在のクリップボードのテキストを編集できます。編集がキャンセルされた場合、テキストは貼り付けられません。
(ショートカット:ctrl+shift+v)
 [Command]
 Command="
     copyq:
     var text = dialog('paste', str(clipboard()))
     if (text) {
       copy(text)
       copySelection(text)
       paste()
     }"
 GlobalShortcut=ctrl+shift+v
 Icon=\xf0ea
 Name=Edit and Paste

リッチテキストの装飾削除

リッチテキスト(Webページからコピーされたテキストなど)から背景とテキスト色を削除します。
コマンドは、クリップボードにコピーされたテキストに自動的に適用され、メニューから(またはカスタムショートカットを使用して)呼び出されます。
 [Command]
 Automatic=true
 Command="
     copyq:
     var html = str(input())
     html = html.replace(/color\\s*:/g, 'xxx:')
     setData('text/html', html)"
 Icon=\xf042
 InMenu=true
 Input=text/html
 Name=Remove Background and Text Colors

リンク作成

プレーンテキストからインタラクティブリンクを作成します。
 [Command]
 Name=Linkify
 Match=^(https?|ftps?|file|mailto)://
 Command="
     copyq:
     var link = str(input());
     var href = '<a href=\"###\">###</a>';
     write(
       'text/plain', link,
       'text/html', href.replace(/###/g, link)
     );"
 Input=text/plain
 Automatic=true
 Remove=true
 Icon=\xf127

テキストの強調

テキストのすべての出現箇所を強調表示します(text以外と一致させる場合にはx = "text"を変更します)。
 [Command]
 Name=Highlight Text
 Command="
    copyq:
    x = 'text'
    style = 'background: yellow; text-decoration: underline'
 
    text = str(input())
    x = x.toLowerCase()
    lowertext = text.toLowerCase()
    html = ''
    a = 0
    esc = function(a, b) {
        return escapeHTML( text.substr(a, b - a) )
    }
 
    while (1) {
        b = lowertext.indexOf(x, a)
        if (b != -1) {
            html += esc(a, b) + '<span>' + esc(b, b + x.length) + '</span>'
        } else {
            html += esc(a, text.length)
            break
        }
        a = b + x.length;
    }
 
    tab( selectedtab() )
    write(
        index(),
        'text/plain', text,
        'text/html',
            '<html><head><style>span{'
            + style +
            '}</style></head><body>'
            + html +
            '</body></html>'
    )"
 Input=text/plain
 Wait=true
 InMenu=true

HTMLレンダリング

HTMLコードをレンダリングします。
 [Command]
 Name=Render HTML
 Match=^\\s*<(!|html)
 Command="
     copyq:
     tab(selectedtab())
     write(index() + 1, 'text/html', input())"
 Input=text/plain
 InMenu=true

英語に翻訳

Google Translateにテキストを渡す
 [Command]
 Name=Translate to English
 Command="
    copyq:
    text = str(input())
    url = \"https://translate.google.com/#auto/en/???\"

    x = url.replace(\"???\", encodeURIComponent(text))
    html = '<html><head><meta http-equiv=\"refresh\" content=\"0;url=' + x + '\" /></head></html>'

    tab(selectedtab())
    write(index() + 1, \"text/html\", html)"
 Input=text/plain
 InMenu=true

貼付け後クリア

選択アイテムを貼り付け、クリップボードをクリアします。
 [Command]
 Name=Paste and Forget
 Command="
    copyq:
    tab(selectedtab())
    items = selecteditems()
    if (items.length > 1) {
        text = ''
        for (i in items)
            text += read(items[i]);
        copy(text)
    } else {
        select(items[0])
    }
 
    hide()
    paste()
    copy('')"
 InMenu=true
 Icon=\xf0ea
 Shortcut=Ctrl+Return

数式をレンダリング

MathJaxを使用し数式をレンダリングします(例:$$ x = {-b \ pm \ sqrt {b ^ 2-4ac} \ over 2a} $$)。
 [Command]
 Name=Render Math Equations
 Command="
    copyq:
    text = str(input())
    js = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
 
    html = '<html><head><script type=\"text/javascript\" src=\"' + js + '\"></script></head><body>' + escapeHTML(text) + '</body></html>';
 
    tab(selectedtab())
    write(index() + 1, 'text/html', html)"
 Input=text/plain
 InMenu=true
 Icon=\xf12b

画像を他タブに移動

このコマンドがアクティブな場合、画像は最初のタブに保存されません。これにより、メインウィンドウが表示されたときやクリップボードが初めて保存されたときに大きな画像データを読み込む必要がないため、アプリケーションが少し速くなります。
 [Command]
 Name=Move Images to Other Tab
 Input=image/png
 Automatic=true
 Remove=true
 Icon=\xf03e
 Tab=&Images

コピーウインドウと同名のタブに追加

このコマンドは、コピー操作が実行されたウィンドウのタイトルと同じ名前のタブに新しいクリップボードを自動的に追加します。
 [Command]
 Name=Window Tabs
 Command="copyq:
    item = unpack(input())
    window_title = item[\"application/x-copyq-owner-window-title\"]
    if (window_title) {
        // Remove the part of window title before dash
        // (it's usually document name or URL).
        tabname = str(window_title).replace(/.* (-|\x2013) /, \"\")
        tab(\"Windows/\" + tabname)
        write(\"application/x-copyq-item\", input())
    }
    "
 Input=application/x-copyq-item
 Automatic=true
 Icon=\xf009

クリップボードの内容を表示

クリップボード内テキスト付きの通知をすばやくポップアップします。
ショートカット:Win + Alt + C
 [Command]
 Name=Show clipboard
 Command="
    copyq:
    seconds = 2;
    popup(\"\", clipboard(), seconds * 1000)"
 GlobalShortcut=Meta+Alt+C

選択文字を全て置換

 [Command]
 Name=Replace in Selection
 Command="
    copyq:
    // Copy without changing X11 selection (on Windows you can use "copy" instead).
    function copy2() {
      try {
        var x = config('copy_clipboard')
        config('copy_clipboard', false)
        try {
          copy.apply(this, arguments)
        } finally {
          config('copy_clipboard', x)
        }
      } catch(e) {
        copy.apply(this, arguments)
      }
    }
 
    copy2()
    var text = str(clipboard())
 
    if (text) {
      var r1 = 'Text'
      var r2 = 'Replace with'
      var reply = dialog(r1, '', r2, '')
 
      if (reply) {
        copy2(text.replace(new RegExp(reply[r1], 'g'), reply[r2]))
        paste()
      }
    }"
 Icon=\xf040
 GlobalShortcut=Meta+Alt+R

N番目のアイテムをコピー

押されたショートカットキーに応じて、アイテムの行をコピーします。例えば、Ctrl + 2の場合行「2」のアイテム。
 [Command]
 Name=Copy Nth Item
 Command="
    copyq:
    var shortcut = str(data(\"application/x-copyq-shortcut\"))
    var number = shortcut ? shortcut.replace(/^\\D+/g, '') : currentItem();
    selectItems(number)
    copy(\"application/x-copyq-item\", pack(getItem(number)))"
 InMenu=true
 Icon=\xf0cb
 Shortcut=ctrl+1, ctrl+2, ctrl+3, ctrl+4, ctrl+5, ctrl+6, ctrl+7, ctrl+8, ctrl+9, ctrl+0
 GlobalShortcut=meta+shift+w, meta+shift+e, meta+shift+q, DISABLED

ファイル編集

 [Command]
 Name=Edit Files
 Match=^([a-zA-Z]:[\\\\/]|~|file://|%\\w+%|$\\w+|/)
 Command="
    copyq:
    var editor = config('editor')
        .replace(/ %1/, '')
 
    var filePaths = str(input())
        .replace(/^file:\\/{2}/gm, '')
        .replace(/^\\/(\\w):?\\//gm, '$1:/')
        .split('\\n')
 
    var args = [editor].concat(filePaths)
 
    execute.apply(this, args)"
 Input=text/plain
 InMenu=true
 Icon=\xf040
 Shortcut=f4

監視状態を永続的に変更する

 [Command]
 Automatic=true
 Command="
    copyq:
    var option = 'disable_monitoring'
    var disabled = str(settings(option)) === 'true'
 
    if (str(data('application/x-copyq-shortcut'))) {
      disabled = !disabled
      settings(option, disabled)
      popup('', disabled ? 'Monitoring disabled' : 'Monitoring enabled')
    }
 
    if (disabled) {
      disable()
      ignore()
    } else {
      enable()
    }"
 GlobalShortcut=meta+alt+x
 Icon=\xf05e
 Name=Toggle Monitoring

ウインドウ名をタグ表示

新しいアイテムのソースアプリケーションのウィンドウタイトルをタグ表示します
 [Command]
 Automatic=true
 Command="
    copyq:
    var window = str(data('application/x-copyq-owner-window-title'))
    var tagsMime = 'application/x-copyq-tags'
    var tags = str(data(tagsMime)) + ', ' + window
    setData(tagsMime, tags)"
 Icon=\xf009
 Name=Store Window Title

コピー日時をタグ表示

新しいアイテムのコピー日時をタグ表示します
 [Command]
 Automatic=true
 Command="
    copyq:
    var time = dateString('yyyy-MM-dd hh:mm:ss')
    setData('application/x-copyq-user-copy-time', time)
 
    var tagsMime = 'application/x-copyq-tags'
    var tags = str(data(tagsMime)) + ', ' + time
    setData(tagsMime, tags)"
 Icon=\xf017
 Name=Store Copy Time

選択アイテムを強調表示

選択アイテムの強調表示を切り替えます。
 [Command]
 Command="
    copyq:
    var color = 'rgba(255, 255, 0, 0.5)'
    var mime = 'application/x-copyq-color'

    var firstSelectedItem = selectedItems()[0]
    var currentColor = str(read(mime, firstSelectedItem))
    if (currentColor != color)
      setData(mime, color)
    else
      removeData(mime)"
 Icon=\xf1fc
 InMenu=true
 Name=Mark/Unmark Items
 Shortcut=ctrl+m

選択テキストの大文字/小文字化

選択テキストの大文字小文字を変更します
 [Command]
 Command="
    copyq:
    if (!copy())
      abort()
 
    var text = str(clipboard())
 
    var newText = text.toUpperCase()
    if (text == newText)
      newText = text.toLowerCase()
 
    if (text == newText)
      abort();
 
    copy(newText)
    paste()"
 GlobalShortcut=meta+ctrl+u
 Icon=\xf034
 Name=Toggle Upper/Lower Case

メンバーのみ編集できます