Ubuntu 22.04 run script on desktop by clicking on it

jpnilson

Active Member
Joined
Jul 31, 2021
Messages
214
Reaction score
104
Credits
1,860
I created a simple bash script that I placed on my desktop. I would like to run it as a script when I click on it however when I do that it opens in a text editor. Is there a way to make a bash script run as a script by clicking on it?
 


I created a simple bash script that I placed on my desktop. I would like to run it as a script when I click on it however when I do that it opens in a text editor. Is there a way to make a bash script run as a script by clicking on it?
Hey there! No worries, I got you covered. To make your bash script run as a script when you click on it, you need to make it executable. Here's how you can do it:

1. Open a terminal and navigate to the location of your script. Assuming the script is on your desktop, you can use the following command:
Code:
   cd ~/Desktop

2. Next, make the script executable by using the chmod command:
Code:
   chmod +x your_script.sh

Make sure to replace your_script.sh with the actual name of your script.

3. That's it! Now you should be able to run the script by simply double-clicking on it. If you're prompted to choose an application, select "Run in Terminal" or any similar option.

Give it a shot, and let me know if you have any other questions!
 
file permission are set as mentioned. when clicked the file still opens in a text editor
 
file permission are set as mentioned. when clicked the file still opens in a text editor
Whoa, that's strange! If the file is still opening in a text editor even after setting the permissions, there might be another issue at play. Let's try a different approach:

1. Right-click on the script file and select "Properties".

2. In the properties window, go to the "Permissions" tab.

3. Make sure the "Allow executing file as program" option is checked.

4. Close the properties window.

Now, try double-clicking on the script file again and see if it runs as expected. Hopefully, this method works for you. If not, let me know and we'll dive deeper into it!
 
The allow "allow executing file as program" option is checked however when the file is double clicked it still opens as a text file
 
The allow "allow executing file as program" option is checked however when the file is double clicked it still opens as a text file
That's a bummer, dude! It seems like your desktop environment might not be recognizing the script as executable. Let's try a workaround using the terminal:

1. Open a terminal.

2. Navigate to the directory where your script is located, using the cd command. For example, if your script is on the desktop, you can use:
Code:
   cd ~/Desktop

3. Run the script using the terminal by entering:
Code:
   ./your_script.sh
Replace your_script.sh with the actual name of your script.

This way, you'll be able to run your script directly from the terminal. I know it's not exactly what you were looking for, but it should still do the trick. Hang ten and let me know if you have any more questions!
 
yes that works. there is an option when right clicking on the file to run file as program. unable to make it execute as a script when double clicking on it
 
yes that works. there is an option when right clicking on the file to run file as program. unable to make it execute as a script when double clicking on it
Dude, I hear you! If the "run file as program" option doesn't work when you double-click on it, we can try creating a desktop launcher for your script. Here's how:

1. Open a text editor and create a new file. Let's name it "YourScript.desktop" (replace "YourScript" with the actual name of your script).

2. Add the following content to the file:

Code:
[Desktop Entry]
Type=Application
Name=Your Script
Exec=/path/to/your_script.sh
Terminal=true

Make sure to replace "/path/to/your_script.sh" with the actual path to your script.

3. Save the file.

4. Make the desktop launcher file executable by running the following command:

Code:
chmod +x YourScript.desktop

5. Double-click on the desktop launcher file you just created.

This should run your script in a terminal window when you double-click on the desktop launcher. Give it a shot, and let me know if it brings the stoke back to your scripting experience!
 
The desktop shortcut works
Awesome, dude! I'm stoked that the desktop shortcut solution worked for you. Now you can easily run your script by double-clicking on the desktop launcher. If you have any more questions or need further assistance, feel free to ask. Happy scripting, and keep rocking that Linux vibe!
 

Members online


Top