How do I create a button on my taskbar along with the time and stuff that performs a specific task? I wanted to be able to disable and enable my keyboard with the help of a keyboard shortcut, but I realized that once I disabled my keyboard with a shortcut, I wouldn't be able to use the keyboard to enable it again. So, I want a button on my taskbar that does this for me with the click of a button, thus not requiring my keyboard.
Thanks.
this can be achieved by creating gnome-shell-extension.
Tested in gnome-shell --version 3.38.1
Run below commands one by one to create required files.
extension.js
file contents, copy paste in above createdextension.js
file. Notice the 11th line,Util.spawnCommandLine("bash /home/admin/mykbd.sh")
replace/home/admin/mykbd.sh
with path of your script that toggles what you are looking for.metadata.json
file contents, copy paste in above createdmetadata.json
file.once you are done with copy pasting in the two files. Refresh the gnome-shell with Alt+F2 r Enter method or logout and login.
Then to enable the extension, run below command.
Again Refresh the gnome-shell with Alt+F2 r Enter method or logout and login.
Now you will see the keyboard button at the top right corner. when you click it, it runs the script you prepared.
Please note that, extensions are disabled when screen is locked and enabled once unlocked. So you wont be able to click this button on lock screen.
A very elegant solution has been provided in this answer by UnKNOWn, but it is rather technical. For completeness, I would want to add a more straightforward method using desktop launchers, yet in this particular case, I would go for the approach of UnKNOWn.
You can at any time create a custom desktop launcher that runs your command or script. Placed in an appropriate location, it will appear in the Applications overview, from where you can pin it to the dash. In Ubuntu, you also could place it on your desktop to launch it from there.
A desktop launcher is a text file with the
.desktop
extension, formatted in a specific way. If you place it in the folder.local/share/applications
, it will be picked up in the application overview.Thus, you could create the file
~/.local/share/applications/toggle-keyboard.desktop
to launch your script. The contents should look like:A bit of a nuclear suggestion, but other optional desktops like MATE or Metacity (and probably others), still offer the "Create Custom Launcher" option through a mouse-click on the panel.