[Solved] Executing a Script from a Keyboard Shortcut

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Josh117

[Solved] Executing a Script from a Keyboard Shortcut

Post by Josh117 »

Over the past few days, I have been looking for a way to make a script run after pressing a keyboard shortcut. After some searching online, I was not able to find a solution.

I want to be able to have a message box pop up that says "Linux is NOT Windows" whenever you press Ctrl-Alt-Del (because I like my computer to have personality :D).

This is my script:

Code: Select all

#!/bin/bash

zenity --warning --title='Ctrl-Alt-Del' --text='Linux is NOT Windows!'
exit 0
Then, I used the Commands plugin in Compiz to run the script and binding <Control><Alt>Delete to the command.

Unfortunately, this only resulted in every opened program to lock up for some reason...

I understand that there are some sources of error that could be the reason this does not work, such as Compiz doesn't allow this kind of thing, or I wrote the script wrong, and so on, but I do not know which one it is.

If someone could help me with this, it would be much appreciated.

Josh
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29607
Joined: Wed Jul 06, 2011 3:58 am

Re: Executing a Script from a Keyboard Shortcut

Post by xenopeek »

Open "Keyboard Shortcuts" from the menu. Add a new shortcut. Give it some name, and type the full path to your script, like so:

Code: Select all

bash -c /home/somebody/somewhere/myscript.bash
Then find your shortcut by name again, at the bottom of the list in the main window. Click at the end to set the keyboard shortcut.
Image
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Executing a Script from a Keyboard Shortcut

Post by Pilosopong Tasyo »

You can forgo the script and directly add the whole zenity line in the Command field. It's only a one-liner anyway. :wink:
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
Josh117

Re: Executing a Script from a Keyboard Shortcut

Post by Josh117 »

Thanks for the solutions; they both work wonderfully. Now I can't wait for a Windows user to fall into my trap...
Locked

Return to “Scripts & Bash”