How to create a desktop shortcut in Ubuntu 20.04
Sometimes in linux, we don’t get a proper installer for an application. To run such application, we typically have to execute a shell script in the application bundle. In this post, we will see how to create a desktop shortcut in Ubuntu 20.04
The need for a desktop shortcut.
Navigating to applications’ binary everytime we need to run it can be a bit annoying, as well as time consuming. While there are some enthusiats who love this, there is also a section of users that wishes to have a shortcut so that, executing your favourite program is just a matter of clicking an icon. Afterall, why compromise accessibility just because you are on linux? 🙂
Creating desktop shortcut – tools vs manual method
While there are many useful tools like Gnome tweak tool, we will follow the manual route. We will create a something.desktop file in /usr/share/applications/. The application for which we will be creating this shortcut for is a famous IDE called PHPStorm and its trial version can be downloaded here
TLDR
Open up your terminal and create a file in /usr/share/applications/.
nano /usr/share/applications/phpstorm.desktop
Download and extract the package. Move the extracted folder to /opt/
tar -xvf PhpStorm-203.7148.74.tar.gz #name of your downloaded package. sudo mv PhpStorm-203.7148.74 /opt/
Create a file phpstorm.desktop in /usr/share/applications/
sudo nano /usr/share/applications/phpstorm.desktop
Paste following code in the file
[Desktop Entry] Name=PHPStorm Type=Application Terminal=false Icon=/opt/PhpStorm-203.7148.74/bin/phpstorm.png #path to application icon. If this icon is not present in your application bundle, you can use anyother image Exec=/opt/PhpStorm-203.7148.74/bin/phpstorm.sh #path to application binary, that needs to be executed to launch the application Categories=Development
Now when you open your applications window, you should see an entry for PHPStorm as well.
You can now simply click this icon to launch your application, instead of manually executing shell script each time :).
Following above steps will create a desktop shortcut for any such application, however running application from shortcut created using this method can add a duplicate icon in the launcher. To prevent this, we need to add one more attribute to our phpstorm.desktop file, but first, we need to get the value of this attribute. To do this,
- Launch the application i.e. Phpstorm.
- type following in terminal
xprop WM_CLASS
After running above command, the cursor should turn to crosshair. Now, click on the application for which you are creating the shortcut, Phpstorm in this case. In the terminal you should see something like
WM_CLASS(STRING) = "jetbrains-phpstorm", "jetbrains-phpstorm"
Copy the value in quotes – “jetbrains-phpstorm”. In phpstorm.desktop file, add following
StartupWMClass=jetbrains-phpstorm
Restart the application, now you should not see duplicate icon in launcher.