The Basics
Today we’re going to talk a bit about tweaking the taskbar on demand. By the end of this tutorial, you will be able to replicate what you are about to see in the video below.
Let’s start by seeing what is currently on your taskbar with the dconf read command.
It should return something similar to this.
['myapp1.desktop', 'myapp2.desktop', 'myapp3.desktop', 'myapp4.desktop', 'myapp5.desktop', 'myapp6.desktop', 'myapp7.desktop', 'myapp8.desktop', 'myapp9.desktop', 'myapp10.desktop', 'myapp11.desktop', 'myapp12.desktop', 'myapp13.desktop', 'myapp14.desktop', 'myapp15.desktop']
Every myapp.desktop in your result represents a launcher in your taskbar. You can use the dconf write command to update your taskbar with new launchers.
If you don’t know the name of a specific launcher that you want, just find the launcher in your apps and manually pin it to your taskbar, then you can run the dconf read command again and it will give you the name.
Automation
You can add this command into a bash script. If you don’t know how to create a bash script, check out this tutorial. -> Bash Scripting Basics
#!/bin/bash dconf write /org/gnome/shell/favorite-apps "['mynewapp1.desktop', 'mynewapp2.desktop', 'mynewapp3.desktop', 'mynewapp4.desktop', 'mynewapp5.desktop', 'mynewapp6.desktop', 'mynewapp7.desktop', 'mynewapp8.desktop', 'mynewapp9.desktop', 'mynewapp10.desktop', 'mynewapp11.desktop', 'mynewapp12.desktop', 'mynewapp13.desktop', 'mynewapp14.desktop', 'mynewapp15.desktop']"
You can make as many of these custom taskbar scripts as you want. Then simply set a different keyboard combo for each one and you can instantly swap between them.
Create Custom Launchers for Your Scripts
You can create custom launchers for your scripts as well. Begin by creating a file with the .desktop extension in the ~/.local/share/applications directory.
Copy and paste the following into the file. Set the name to whatever you wish and then set the path to the script you want to launch. When you’ve finished, save the file and your launcher will appear in your applications list.
[Desktop Entry] Name=MyLauncher Exec=/path/to/your/script.sh Terminal=false Type=Application
If you have an image you’d like to use as an icon for the launcher, you can add it with this.
[Desktop Entry]
Name=MyLauncher
Exec=/path/to/your/script.sh
Terminal=false
Type=Application
Icon=/path/to/your/image.png
You can also create launchers for your favorite social media websites. In this example we will create a script to open facebook.com in Google Chrome.
#!/bin/bash google-chrome "https://www.facebook.com"
And then we’ll make a launcher for it in the ~/.local/share/applications directory and presto! Instant Facebook launcher. Don’t forget to save the file with the .desktop extension.
[Desktop Entry] Name=Facebook Exec=/path/to/your/script.sh Terminal=false Type=Application Icon=/path/to/some_facebook_icon_that_i_downloaded_with_a_quick_google_search.png
Spice It Up
Remember the command from my Rotating Desktop Backgrounds tutorial?
Yeah. Throw that into your script to change the background when your taskbar swaps.
#!/bin/bash
gsettings set org.gnome.desktop.background picture-uri '/path/to/myimage.png' && dconf write /org/gnome/shell/favorite-apps "['mynewapp1.desktop', 'mynewapp2.desktop', 'mynewapp3.desktop', 'mynewapp4.desktop', 'mynewapp5.desktop', 'mynewapp6.desktop', 'mynewapp7.desktop', 'mynewapp8.desktop', 'mynewapp9.desktop', 'mynewapp10.desktop', 'mynewapp11.desktop', 'mynewapp12.desktop', 'mynewapp13.desktop', 'mynewapp14.desktop', 'mynewapp15.desktop']"
Not enough? Still need more? Add a transition sound to it.
#!/bin/bash
gsettings set org.gnome.desktop.background picture-uri '/path/to/myimage.png' && dconf write /org/gnome/shell/favorite-apps "['mynewapp1.desktop', 'mynewapp2.desktop', 'mynewapp3.desktop', 'mynewapp4.desktop', 'mynewapp5.desktop', 'mynewapp6.desktop', 'mynewapp7.desktop', 'mynewapp8.desktop', 'mynewapp9.desktop', 'mynewapp10.desktop', 'mynewapp11.desktop', 'mynewapp12.desktop', 'mynewapp13.desktop', 'mynewapp14.desktop', 'mynewapp15.desktop']" && mplayer '/path/to/mysound.mp3'
For the most part, I tend to swap back and forth between 2 main taskbars, so I wrote the following script to allow swapping back and forth between the 2 with a single key combination instead of having a separate script and key combo for each. This script will read your current taskbar and if it detects your first taskbar, it will swap to the second taskbar and second background. If it does not detect the first taskbar, it will swap to the first taskbar and first background. It plays the same sound regardless of which way it swaps, but of course you can change that if you really want to. Edit the red sections.
#!/bin/bash bg1='/path/to/background1.jpg' bg2='/path/to/background2.jpg' sound='/path/to/mysound.mp3' tbar1="['myapp1.desktop', 'myapp2.desktop', 'myapp3.desktop', 'myapp4.desktop', 'myapp5.desktop', 'myapp6.desktop', 'myapp7.desktop', 'myapp8.desktop', 'myapp9.desktop', 'myapp10.desktop', 'myapp11.desktop', 'myapp12.desktop', 'myapp13.desktop', 'myapp14.desktop', 'myapp15.desktop']" tbar2="['mynewapp1.desktop', 'mynewapp2.desktop', 'mynewapp3.desktop', 'mynewapp4.desktop', 'mynewapp5.desktop', 'mynewapp6.desktop', 'mynewapp7.desktop', 'mynewapp8.desktop', 'mynewapp9.desktop', 'mynewapp10.desktop', 'mynewapp11.desktop', 'mynewapp12.desktop', 'mynewapp13.desktop', 'mynewapp14.desktop', 'mynewapp15.desktop']" check=$(dconf read /org/gnome/shell/favorite-apps) if [ "$check" == "$tbar1" ] then $(gsettings set org.gnome.desktop.background picture-uri "file://$bg2" && dconf write /org/gnome/shell/favorite-apps "$tbar2" && mplayer "$sound") else $(gsettings set org.gnome.desktop.background picture-uri "file://$bg1" && dconf write /org/gnome/shell/favorite-apps "$tbar1" && mplayer "$sound") fi
That’s all for today. May your future be filled with awesomeness and baby Yodas.