Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I escape quotes in .xbindkeysrc commands? Neither of those work.

"pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3+2500)}'"

"pacmd dump|awk --non-decimal-data '\$1~/set-sink-volume/{system ("pacmd "\$1" "\$2" "\$3+2500)}'"

"pacmd dump|awk --non-decimal-data '\$1~/set-sink-volume/{system (\"pacmd \"\$1\" \"\$2\" \"\$3+2500)}'"

"pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system (\"pacmd \"$1\" \"$2\" \"$3+2500)}'"

(The commands raises the PulseAudio volume level)

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

There's two separate issues here, and I'll try to address both.

The first is how to correctly quote a command in .xbindkeysrc.

All you have to do is take a command that works in bash, then put double quotes around it.

For example, for a command with a space in it, you'd have to run

"/home/user/My Programs/progname"

or

/home/user/My\ Programs/progname

in bash.

Which means you need

""/home/user/My Programs/progname""

or

"/home/user/My\ Programs/progname"

in your .xbindkeysrc.

Technically what's happening is that xbindkeys removes the outermost pair of double quotes, then runs the remaining string using sh -c.


In your example, the command

pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3+2500)}'

works fine in bash, so I think the problem is elsewhere.

Try running xbindkeys with the -v option, which makes xbindkeys run in the foreground, so you can see any errors on your terminal.

In my case, it shows the underlying cause is not bad quoting, but pacmd giving an error

...
No PulseAudio daemon running, or not running as session daemon.

but if you have PulseAudio working, I think you need to change pacmd to pactl, because the man page says that pacmd doesn't take arguments, and several other examples on the web show using pactl for this purpose.

share|improve this answer
1  
Thanks, putting the command in double quotes with no escaping at all worked :) –  Danilo Bargen Nov 6 '12 at 12:25
add comment

As a workaround, create a shell script ~/bin/mychangevolume with the commands non-escaped as they would appear on the command line. Something like

#!/bin/bash
incr=$1
pacmd dump | awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3'$incr')}'"

Then call this script from .xbindkeysrc

"mychangevolume +2500"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.