How can I enable bash expansion by custom keyboard shortcuts in 14.04? Here's an example that I've been trying to get setup; I want to execute this exact command (which works from a terminal running bash):

gnome-screenshot --window --remove-border -f ~/Pictures/screenshot_$(date +%x_%H:%M:%S:%N).png

It doesn't work as is, and neither does:

gnome-screenshot --window --remove-border -f $HOME/Pictures/screenshot_$(date +%x_%H:%M:%S:%N).png

If I change it to the following:

gnome-screenshot --window --remove-border -f "/home/user/Pictures/screenshot_$(date +%x_%H:%M:%S:%N).png"

I end up with a file on my desktop called "screenshot_$(date +%x_%H:%M:%S:%N).png" (no subshell expansion). What am I doing wrong? What executes these commands if not bash? Why aren't the subshells or variables/tildes expanded?


The keyboard shortcuts field in Unity works in a similar manner to .desktop files, i.e. commands are executed without any form of subshell or variable expansion and can't access any environment variables.

I wasn't able to find an official specification regarding the keyboard shortcuts menu but I think it's save to assume that command execution follows similar guidelines to the Exec field in XDG .desktop files.

What this means, in practice, is that there are two ways you can make your custom command-line work with the shortcuts menu:

  1. Transform your commands into a simple shell script and point the keyboard shortcut to the shell script.

    For instance, you could paste the following into a new text file, name it something like custom_screenshot_script and make the script executable:

    gnome-screenshot --window --remove-border -f "~/Pictures/screenshot_$(date +%x_%H:%M:%S:%N).png"
  2. Call bash to execute your command.

    This is more tricky because you have to escape your arguments correctly. Something like the following should work:

    bash -c "gnome-screenshot --window --remove-border -f \"~/Pictures/screenshot_$(date +%x_%H:%M:%S:%N).png\""

In my case I would make a script:


Case (window_border) in ~./picture

    gnome-screenshot --window ~/picture/screenshot_$(date+%X_% H:$M:$:$S:$n)*png

    Bash -i remove-border -f window

    Bash --window --remove-border -f ''~/picture/screenshot_$(date+%X_%H:$M:$:$S:$N).png''


and it might work Fine This Way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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