hluk / copyq-commands

Useful commands for CopyQ clipboard manager.
339 stars 73 forks source link

Play sound when pasting to Windows #49

Closed timtrace closed 2 years ago

timtrace commented 2 years ago

Greetings, I've been trying to come up with a global command to play a sound when pasting to windows. I can't get it to work, exceptions keep getting thrown at me. Is it allowed to ask for guidance here?

This is my "Play Sound on Copy" command, which plays a sound and copies the selected text to the clipboard and copyq ...

[Command]
Name=Play Sound on Copy
Command="
     powershell:
    $mydocuments=[environment]::getfolderpath(\"mydocuments\");(New-Object Media.SoundPlayer \"$mydocuments\\MMT\\CopyQ\\sounds\\WoodClickUp.wav\").PlaySync()"
Automatic=true
Icon=\xf028

Log says: CopyQ Note [2021-10-22 12:53:19.713] <Client-23948>: Command "Play Sound on Copy": Finished in 1424 ms

And this is my "Play Sound on Paste" command, which doesn't work. No sound is produced, and nothing is pasted.

[Command]
Name=Play Sound on Paste
Command="
     powershell:
    $mydocuments=[environment]::getfolderpath(\"mydocuments\");(New-Object Media.SoundPlayer \"$mydocuments\\MMT\\CopyQ\\sounds\\WoodClickDown.wav\").PlaySync()
     copyq: paste()"
IsGlobalShortcut=true
Icon=\xf028
GlobalShortcut=ctrl+v

Log says: 
CopyQ Note [2021-10-22 12:53:29.908] <Server-31728>: Command “Play Sound on Paste”
CopyQ Note [2021-10-22 12:53:29.908] <Server-31728>:    Exit code: 1
CopyQ Note [2021-10-22 12:53:29.908] <Server-31728>:    1. powershell $mydocuments=[environment]::getfolderpath("mydocuments");(New-Object Media.SoundPlayer "$mydocuments\MMT\CopyQ\sounds\WoodClickDown.wav").PlaySync()
CopyQ Note [2021-10-22 12:53:29.908] <Server-31728>:    2.  copyq: paste()

Please tell me what I'm doing wrong - and thank you so much.

hluk commented 2 years ago

Nesting labels like copyq: under another label (powershell:) is not supported. You need to call copyq from the powershell environment:

& 'C:\Program Files (X86)\CopyQ\copyq.exe' paste