Aandrew7
Posts: 4
Joined: Sat Jan 20, 2018 8:45 pm

how to keybind a script

Mon Apr 23, 2018 1:17 am

I would like to launch a script (example "name.sh") by a hotkey . something like Ctrl+Alt+T but having the terminal auto run the script.

Aandrew7
Posts: 4
Joined: Sat Jan 20, 2018 8:45 pm

Re: how to keybind a script

Mon Apr 23, 2018 1:27 am

What I ultimately want to have happen is I want to press a button connected to the GPIO which would be a combination of keyboard keys pressed. That "Hotkey" would run a script. Maybe there is a simpler way of having this happen, I don't know.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: how to keybind a script

Mon Apr 23, 2018 5:04 am

Aandrew7 wrote:
Mon Apr 23, 2018 1:17 am
I would like to launch a script (example "name.sh") by a hotkey . something like Ctrl+Alt+T but having the terminal auto run the script.
to change and add like screenshots keys config
[print screen]
and add
[alt][print screen]
i do
nano .config/openbox/lxde-pi-rc.xml !! warning , any changes might be overwritten with next upgarde
find example:

Code: Select all

    <keybind key="Print">
      <action name="Execute">
        <command>scrot</command>
      </action>
    </keybind>
the snap file ends up at /home/pi/
with windows style for [print] and [alt][print] for active window only

Code: Select all

<!-- KLL -->
    <keybind key="A-Print">
      <action name="Execute">
        <command>scrot -u Pictures/%Y-%m-%d_%H-%M-%S_snap.png</command>
      </action>
    </keybind>
    <keybind key="Print">
      <action name="Execute">
        <command>scrot Pictures/%Y-%m-%d_%H-%M-%S_snap.png</command>
      </action>
    </keybind>
<!-- end KLL -->
now need to update: do reboot

also find
[C-A-T] is used already
it opens a terminal ( did you try that? )

if you call your own script, better use full path to it.
nano /home/pi/my_script.sh

Code: Select all

#!/bin/bash
# ~/my_script.sh / made executable / called by desktop [ctrl][alt][s]
lxterminal &
gpicview &
chmod +x my_script.sh

nano /home/pi/.config/openbox/lxde-pi-rc.xml
and add

Code: Select all

     <keybind key="C-A-S">
      <action name="Execute">
        <command>bash /home/pi/my_script.sh</command>
      </action>
    </keybind>
reboot and test

Code: Select all

 [ctrl][alt][s]

Return to “Beginners”