XFCE keybind to run a script

Hi, I used to have a bash script that I run with custom keybind (Alt+Shift+O), after the update the keybind no longer works.
I tried to re-set it again, but the script doesn’t run anymore, I know because the script calls fro notify-send.
And I can run the script just fine when executed in terminal.
Any idea?

HHHHmmmm…, confirm Alt+Shift+O,

Via command:

xfconf-query -c xfce4-keyboard-shortcuts -l -v  | grep -i '<alt><shift>'

Or grep file directly:

grep -i 'YourScriptName' ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml

I am assuming the shortcut was set via XFCE Settings > Keyboard > Applications (if other, please provide details), and exists in a directory that is in your PATH.

While you execute the shortcut or the script, follow .xessions-errors in another terminal to see if there are any errors.

Add a debugging line like below, which will appear in the journal, as well as .xsession-errors.

logger --id "$$" --priority 'info' --stderr  'Message'
tail -f ~/.xsession-errors
journalctl -f

Doc: man logger

1 Like

OK, I’ve run this, and for whatever reason, the shortcut is not saved.

It could be <shift><alt> so check reversed as well (e.g. I have that in my files, recorded as usual) - but best to check the file directly as @stargazer suggested (grep-ing for your script name - you can view it manually, it’s not that long). If you don’t have the command then just re-add and try again.

I did as you suggested and you were right, it was
Anyway, nothing shows up in .xsession-errors regarding the script or the keybind.

The shortcuts/keybindings willl only show via xfconf-query or by viewing the file directly if the shortcut was added through XFCE Settings (see post above).

Could you provide additional details.

There are other ways on the XFCE desktop using the bash shell to set shortcuts that are similar but for different reasons and effects (xfce4-terminal you need to edit accels.scm, readline bind, etc) which would not show up. The OP mentioned that you “re-set it”. How? The more details the quicker we can help :slight_smile:

xfconf-query should either report that the keyboard shortcut for <Alt><Shift>o does not exist:

$ xfconf-query --channel xfce4-keyboard-shortcuts --property "/commands/custom/<Alt><Shift>o" 
Property "/commands/custom/<Alt><Shift>o" does not exist on channel "xfce4-keyboard-shortcuts".

Or confirm the command to run the script:

$ xfconf-query --channel xfce4-keyboard-shortcuts --property '/commands/custom/<Primary><Alt>o'
/usr/bin/sh /home/nik/.local/bin/script

If the keyboard shortcut does not exist, use a command similar to this to create it, change the command to the required script

xfconf-query --create --channel xfce4-keyboard-shortcuts --property "/commands/custom/<Primary><Alt>o" --type string  --set "/usr/bin/sh /home/nik/.local/bin/script"

I mean, I deleted the entry from the keyboard shortcuts menu and re-adding it.
I’m not sure what change, since the last update because it was working fine.
I’m certain it’s xfce issue, since my KDE manjaro still works fine.

Well, xfconf-query does detect the script, only if I swap the alt and shift positions, in the search.
I tried to change the keybind as well but didn’t help.

I suggest check xfce4-keyboard-shortcuts channnel in xfce4-settings-editor. If the shortcut is not present, press the + Add button to create it

also suggest making a 2nd shortcut with only one modifier key to avoid further confusion with search terms

The shortcut is present in xfce4-keyboard-shortcuts, I even tried adding it there.
Still didn’t work.
Even after changing to one modifier.
What’s the correct way to keybind a script?
Just add the path to a script and set it to be executable?

If the shortcut is present in xfce4-settings-editor, press the 🖉 Edit button, copy the command to run the script and paste it here

I also suggest you check the script for errors at shellcheck.net and post a copy of the script here

the script runs fine, I’ve checked it by running the command in terminal, worked as expected.
But here it is.
/path/to/8ball.sh

And the script
8ball.sh

#!/bin/bash

ans=("It is certain." "It is decidedly so." "Without a doubt." "Yes – definitely." "You may rely on it." "As I see it, yes." "Most likely." "Outlook good." "Yes." "Signs point to yes." "Reply hazy, try again." "Ask again later." "Better not tell you now." "Cannot predict now." "Concentrate and ask again." "Don't count on it." "My reply is no." "My sources say no." "Outlook not so good." "Very doubtful.");
notify-send "${ans[$((RANDOM%${#ans[@]}))]}"

Would it be correct to assume that /path/to/ is an obfuscation of the folder location?

I suggest changing the shortcut command to – /usr/bin/sh /path/to/8ball.sh
with the correct full path to the folder location

e.g. working shortcut on my system: /usr/bin/sh /home/nik/.local/bin/8ball.sh

1 Like

Yeah, it’s an obfuscation.
And no, that didn’t work either.
Honestly I don’t know what’s wrong at this point.
I checked the file permissions, checked the location, checked if the script work on it’s own.
All were OK.
But for some reason, the script won’t work when I use the keybind.

Perhaps I missed it, but did you view ~/.xession-errors or the journalctl as mentioned in the first reply?

Short:

Add echo’s, check return codes, check logs.

Long:

Try something really simple to narrow the scope of the problem. Add echo’s to see how far you are getting in your script as a shortcut.

I created a short test (see below) and it worked. Added in your snippet above and it also worked.

Comment out code or add an exit, test, and remove some of the comments or move the exit down, and test again (inch-by-inch anything is a cinch). Perhaps the problem is another command or a missing environmental variable. Check the return code of commands ($?).

I believe you mentioned only notify-send.sh. I use it all the time. It has to be installed from the AUR. The version of notify-send.sh is 1.2-1 and resides in /usr/bin (note: /bin is a symlink to /usr/bin). Other commands could have their own issues, so check the return code.

pamac search notify-send.sh

type -a notify-send.sh

Short test

  1. nano myscript.sh
#!/bin/bash
notify-send "hello" "This is a test"
rc=$?
echo $0 $rc >&2
echo $0 $rc >/home/$USER/myscript.log
#
#
exit
  1. chmod u+x myscript.sh

  2. Execute xfce4-keyboard-settings (can also get there by going to XFCE Settings Manager)

  3. Select the tab “Application Shortcuts”

  4. “Click +Add”

  5. Enter the FULL PATH to your script

  6. Click Ok

  7. Enter the shortcut key

    NOTE: Steps 3-8 can be replaced with the xfconf-query command. See @nikgnomic reply.

  8. Scroll in the list and you should see the shortcut

  9. Test your shortcut

I did all those, still didn’t work.
However, choosing different keybinds solved it.
I switched to Ctrl+Shift+2, and it worked.
Thanks for the help.