Skip to content

[Linux] Double-click to execute shell script and add it to the dock bar

Last Updated on 2021-08-03 by Clay

Sometimes if we want to execute a shell script on Linux, we need to open the terminal and give the command —— it's too slow! If we often need to use this file, for example, the startup file of an application, we may become very anxious. This is why I am looking for how to double-click to execute a shell script on Linux.

I checked many teachings about how to use double-click to run the shell script on Linux on the Internet and most of them proposed to find the document in the upper left corner, then set the properties of the file, and then double-click to execute it. But I can't find the File option in the upper left corner, this method is not suitable for me. I think it is the version difference.

My final solution was to write a .desktop file first, and then write a desktop file on the desktop to double-click to execute. I will start to explain my approach, and take PyCharm (A useful Python IDE) as an example, you need to replace PyCharm with the file you need.


Instructions

First open your terminal and edit a new file:

vim ~/Desktop/pycharm.desktop

Write these commands:

[Desktop Entry]
Name=THE_NAME_OF_PROGRAM
Comment=COMMENT
Exec=sh SHELL_SCRIPT_PATH
Icon=ICON
Terminal=false
Type=Application

Taking PyCharm as an example, the command I wrote is as follows:

[Desktop Entry]
Name=pycharm
Comment=open pycharm IDE
Exec=sh /home/ccs96307/pycharm-community-2018.2.3/bin/pycharm.sh
Icon=/home/ccs96307/pycharm-community-2018.2.3/bin/pycharm.png
Terminal=false
Type=Application

Then the archive exits. At this time, we will see an icon like this on the desktop:

At this time, all steps have not been completed. If executed now, it will appear:

We need to change permissions. Right-click the program, go to the bottom "Properties", and select "Permissions".

Check "Allow the file to be executed as a program (E)", and then close the window.

The program on our desktop will look like this:

Double-click it.

This time, PyCharm was successfully launched!


Add to dock bar

If we want to add the executable file we created to the left dock bar (of course, I'm not sure if your is on the left), we need to use the following command to move the .desktop file we just created to the application area.

cp pycharm.desktop ~/.local/share/applications/

In this way, we can find this application in "Search", of course, you can also add the Dock bar on the left.I hope everyone can successfully configure the files they want to double-click to execute.


References


Read More

Tags:

Leave a ReplyCancel reply

Exit mobile version