Dear Qubes community,
I am looking for a way to execute a command with a keyboard shortcut. For example, the command "screenshot" should start the screenshot program within the respective VM or the command "nautilus" should pop up a file browser window of the VM that is currently being worked with.
If I set up a keyboard combination for this in dom0 in the xfce keyboard settings, then I would have to set a different keyboard combination for each Qube:
Ctrl+Alt+1 for Qube1: qvm-run Qube1 nautilus
Ctrl+Alt+2 for Qube2 qvm-run Qube2 nautilus
So, how can I do the same thing at the qube level instead of in dom0?
You can install the autokey program, but it requires me to write a python script, and I don't know how to express a simple shell command in python.
All the best
I don't have the time currently to figure this out and send you a working solution. So instead I'll share things I know:
1) if you inquire the window property "_QUBES_VMNAME" of the active window, you'll get the name of the qube
2) you should be able to get to this with wmctrl or maybe xdotool
Then write a little bash script in dom0 and hook it up to a shortcut, is what I think.
Here's a script that does exactly this.
Edit it to do something with $QUBE.
Associate it with a shortcut.
QUBE=`xprop _QUBES_VMNAME -id $ID|cut -f2 -d\" `
if [[ "$QUBE" == "_QUBES_VMNAME: not found." ]]; then
# Do something with $QUBE
The if clause is to exclude dom0 windows, but you could adapt that if
you *do* want action in dom0.
Just to riff on this ...
I made a bash script called qvm-run-in-focused-vm that accepts one command as parameter and then uses the structure @unman showed to run that command either in dom0 or the VM that has the focus.
Then I hooked up the following XFCE shortcuts:
Ctrl+Enter --> qvm-run-in-focused-vm xterm
Ctrl+Shift+Enter --> qvm-run-in-focused-vm nautilus
Ctrl+Shift+W --> qvm-run-in-focused-vm "sudo poweroff"
So much goodness!