2

I have a python script named script.py I want to double click on script.desktop, and it will execute the shell file script.sh, which will then evecute the python file: script.py.

My script.desktop file contains:

[Desktop Entry]
Name=jobs
Comment=jobs
Exec=/home/user/Desktop/school_scrape/script.sh
Icon=/home/user/Desktop/school_scrape/icon.png
Terminal=true
Type=Application  

My shell file script.sh thus looks like:

#!/bin/bash
echo "hi"
sleep 2m

I eventually want it to execute a script.py file, upon executing it via the shell file, but itd make sense to first get it to echo hi first

I cant even get it to output the hi though in terminal when i double click script.desktop it just hangs with no error.

First I'd like for it to just run .desktop file, that runs the .sh file, and outputs hi, then ill worry about executing the python file.

Any idea what im doing wrong?

14
  • did you set chmod +x script.py ? then it may run with double click and you don't need script.sh Commented Feb 5, 2017 at 15:35
  • @furas - yea already did that Commented Feb 5, 2017 at 15:36
  • If you have #!/full/path/python in script.py then you can try Exec=/home/user/Desktop/school_scrape/script.py or in script.sh use /full/path/script.py. If you don't have #!/full/path/python in script.py then you need python /full/path/script.py in script.sh Commented Feb 5, 2017 at 15:40
  • @furas please see question, im not looking to get the python file ran right now. All i want to do is get it to output hi in terminal, when i double click on .desktop file, ultimately the goal is to get the python script to run, but hi is a good start Commented Feb 5, 2017 at 15:42
  • to run script (python or sh) you need two things - chmod +x and #!/full/path/python or #!/bin/bash (shebang) in script. Commented Feb 5, 2017 at 15:43

2 Answers 2

2

script.sh

#!/bin/bash
echo "hi"

read

Set chmod +x script.sh and try manually in console/terminal - you may have to add ./ at start to run it

./script.sh

script.desktop

In Linux Mint system adds first line with #! - so maybe it needs it.

#!/usr/bin/env xdg-open
[Desktop Entry]
Name=jobs
Comment=jobs
Exec=/home/user/Desktop/school_scrape/script.sh
Icon=/home/user/Desktop/school_scrape/icon.png
Terminal=true
Type=Application  

Set chmod +x script.desktop and try click it

script.py

#!/usr/bin/env python

print("Hello World!")

input()

Set chmod +x script.py and try manually in console/terminal

./script.py

Add to script.sh - better with full path

#!/bin/bash
echo "hi"

/home/user/Desktop/school_scrape/script.py

(because script.py has shebang and set chmod +x so you don't have to use python in script.sh. You can even remove extension in file and in script)

Or use directly in .desktop

script-py.desktop

#!/usr/bin/env xdg-open
[Desktop Entry]
Name=jobs-py
Comment=jobs-py
Exec=/home/user/Desktop/school_scrape/script.py
Icon=/home/user/Desktop/school_scrape/icon.png
Terminal=true
Type=Application  

Set chmod +x script-py.desktop and try click it

Sign up to request clarification or add additional context in comments.

4 Comments

thanks, this works. Do i just add python script.py to script.sh? I'll accept shortly after. Thank you so much!
you can add python script.py to script.sh or you can use script.py directly in .desktop file.
How can i use directly in .desktop ?
you can use directly in .desktop the same way as script.sh - see new text in answer. script.sh and script.py with correct shebang and chmod +x are treated by Linux the same way.
0

Have you tried to insert the following line in script.sh: python script.py

Or you can make it executable by using command: chmod +x script.py and just write in script.sh: ./script.py

2 Comments

I cant even echo hi nevermind running the python script
Here are useful references: askubuntu.com/questions/138908/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.