XFCE - How does one assign keyboard shortcut to .desktop or to command?

Technical issues/questions of an intermediate or advanced nature.
User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - How does one assign keyboard shortcut to .desktop or to command?

Post#1 by Rava » 19 Oct 2022, 20:37

How does one give .desktop files keyboard assignments in XFCE 4.16?

I have two self-coded .desktop files for monitor rotation, and I would like to assign keyboard shortcuts to both.
One rotates my HDMI-0 left, the other back to normal. (I also have .desktop's for right and inverse but hardly ever use these.)

Code: Select all

guest@porteus:/usr/share/applications$ ls -o monitorrotate-[ln]*|cut -c 19-
207 2021-01-22 18:55 monitorrotate-left.desktop
211 2021-01-22 18:55 monitorrotate-normal.desktop
The command itself being either

Code: Select all

/usr/bin/xrandr --output HDMI-0 --rotate left
for rotate left and

Code: Select all

usr/bin/xrandr --output HDMI-0 --rotate normal
for rotate normal.

I saw somewhere option for assigning keyboard shortcuts in XFCE, but do not recall where, and not even recall if these could be used to assign keyboard commands to specific .desktop files.
If that is not possible, I hope it is possible to assign a keyboard shortcut to a specific command, e.g. to the as quoted above xrandr commands.
Cheers!
Yours Rava

donald
Full of knowledge
Full of knowledge
Posts: 2067
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

XFCE - How does one assign keyboard shortcut to .desktop or to command?

Post#2 by donald » 19 Oct 2022, 22:47

Rava wrote:
19 Oct 2022, 20:37
....assign a keyboard shortcut to a specific command, e.g. to the as quoted above xrandr commands
no words needed, I think. :)

Image

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - How does one assign keyboard shortcut to .desktop or to command?

Post#3 by Rava » 21 Oct 2022, 01:55

donald wrote:
19 Oct 2022, 22:47
no words needed, I think. :)

https://i.postimg.cc/VNhctkRq/rotate.jpg
The issue with using ^L and ^N is: some programs might also use these shortcuts.
Only one example: mousepad:
Image

What would happen then? Would XFCE catch ^L and ^N and the program would not react?
Or would both the screen be turned and the program that also uses whatever ^L or ^N means to it and also do the ^N or ^L task?
Especially annoying when you meant to only do the program ^L or ^N task and not turn the screen…

Another question:
xflock4 is also part of my XFCE 4.16 setup as "Super + L" but when I press that nothing is happening. Could it be that keyboard shortcuts are disabled as long as I have the Keyboard / Application Shortcuts tab open?

Added in 35 minutes 4 seconds:
About xflock4:
I looked into

Code: Select all

/usr/bin/xflock4: POSIX shell script, ASCII text executable
and it says there at the top of the code (disregarding the long comment at top since a comment is no code to be executed)

Code: Select all

# First test for the command set in the session's xfconf channel
LOCK_CMD=$(xfconf-query -c xfce4-session -p /general/LockCommand)

# Lock by xscreensaver or gnome-screensaver, if a respective daemon is running
for lock_cmd in \
    "$LOCK_CMD" \
    "xfce4-screensaver-command --lock" \
    "xscreensaver-command -lock" \
    "gnome-screensaver-command --lock"
do
    if [ ! -z "$lock_cmd" ]; then
        $lock_cmd >/dev/null 2>&1 && exit
    fi
done
so I looked into these 3 programs:

Code: Select all

guest@porteus:~$ which xfce4-screensaver-command
which: no xfce4-screensaver-command in (/usr/local/bin:/usr/bin:/bin:/usr/games)
guest@porteus:~$ which xscreensaver-command
which: no xscreensaver-command in (/usr/local/bin:/usr/bin:/bin:/usr/games)
guest@porteus:~$ which gnome-screensaver-command
which: no gnome-screensaver-command in (/usr/local/bin:/usr/bin:/bin:/usr/games)
And the 1st code is also returning NIL:

Code: Select all

guest@porteus:~$ echo $(xfconf-query -c xfce4-session -p /general/LockCommand)

guest@porteus:~$ 
No wonder then that nothing is happening when pressing the associated keyboard shortcut. :D

Added in 5 minutes 22 seconds:
That means *devious face* I can erase all entries concerning xflock4 and re-use all previously assigned to xflock4 keyboard shortcuts for my monitor-rotating thingys. :magic:

Added in 8 minutes 46 seconds:
Image
ImageImage
(SCNR)

Added in 14 minutes 55 seconds:
And if you not use changes recall to save /home/guest/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml
e.g. to your $PORTDIR/rootcopy/ -> $PORTDIR/rootcopy/home/guest/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - How does one assign keyboard shortcut to .desktop or to command?

Post#4 by Rava » 23 Oct 2022, 19:16

I split the rest of the posts into a new thread -
XFCE - slock and xfce4-screensaver -
since these are all about slock and xfce4-screensaver and no longer about "keyboard shortcut to .desktop or to command"
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - How does one assign keyboard shortcut to .desktop or to command?

Post#5 by Rava » 03 Nov 2022, 01:33

I changed all from HDMI-0 to VGA-0

some diffs on that /usr/share/applications/monitorrotate-* :

Code: Select all

guest@porteus:/mnt/live/memory/images/991-usr_local_bin-RECENT.xzm/usr/share/applications$ diff monitorrotate-inverted /usr/share/applications/monitorrotate-inverted 
2c2
< Exec=/usr/bin/xrandr --output HDMI-0 --rotate inverted
---
> Exec=/usr/bin/xrandr --output VGA-0 --rotate inverted
guest@porteus:/mnt/live/memory/images/991-usr_local_bin-RECENT.xzm/usr/share/applications$ diff monitorrotate-left.desktop /usr/share/applications/monitorrotate-left.desktop 
2c2
< Exec=/usr/bin/xrandr --output HDMI-0 --rotate left
---
> Exec=/usr/bin/xrandr --output VGA-0 --rotate left
guest@porteus:/mnt/live/memory/images/991-usr_local_bin-RECENT.xzm/usr/share/applications$ diff monitorrotate-normal.desktop /usr/share/applications/monitorrotate-normal.desktop 
2c2
< Exec=/usr/bin/xrandr --output HDMI-0 --rotate normal
---
> Exec=/usr/bin/xrandr --output VGA-0 --rotate normal
guest@porteus:/mnt/live/memory/images/991-usr_local_bin-RECENT.xzm/usr/share/applications$ diff monitorrotate-right.desktop /usr/share/applications/monitorrotate-right.desktop
2c2
< Exec=/usr/bin/xrandr --output HDMI-0 --rotate right
---
> Exec=/usr/bin/xrandr --output VGA-0 --rotate right
and XFCE's keyboard settings via ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml :

Code: Select all

guest@porteus:/mnt/live/memory/images/992-rootcopy_5.0-RECENT.xzm/home/guest/.config/xfce4/xfconf/xfce-perchannel-xml$ diff xfce4-keyboard-shortcuts.xml  ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml 
58,59c58,59
<       <property name="&lt;Super&gt;l" type="string" value="/usr/bin/xrandr --output HDMI-0 --rotate left"/>
<       <property name="&lt;Super&gt;n" type="string" value="/usr/bin/xrandr --output HDMI-0 --rotate normal"/>
---
>       <property name="&lt;Super&gt;l" type="string" value="/usr/bin/xrandr --output VGA-0 --rotate left"/>
>       <property name="&lt;Super&gt;n" type="string" value="/usr/bin/xrandr --output VGA-0 --rotate normal"/>
Added in 23 minutes 6 seconds:
If you prefer the menu based way for the 2nd kind of settings - that is via
Image
you jump through some loops. Cave! I chose donald's screenshot (too lazy to make and upload my own, his is suffice), his commands differ a bit from mine, I refer to mine below the same as in the [ code ]-blocks above.

● First you select the correct entry
● press [Edit]
● Edit the entry accordingly, e.g. from

Code: Select all

/usr/bin/xrandr --output HDMI-0 --rotate normal
to

Code: Select all

/usr/bin/xrandr --output VGA-0 --rotate normal
● then you got asked which keys shall be assigned to this command. Cave! This window you cannot move. In the above examples you need to recall if it was the command meant for Super+n or Super+l - press both keys at the same time until the window only displays Super+n in the case of the above example
● Then XFCE tells you that a command for Super+n already exists and gives you a choice between [/usr/bin/xrandr --output HDMI-0 --rotate normal] or [/usr/bin/xrandr --output VGA-0 --rotate normal]
● chose the one you want, in the above example I chose [/usr/bin/xrandr --output VGA-0 --rotate normal]

Now you are all set. And how easy it is via menu.
Compared to opening an editor and replacing all two entries of HDMI-0 with VGA-0 the menu way for both keys is so much quicker. </irony>
Cheers!
Yours Rava

Post Reply