Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How to make shell script to run with mouse click?

  1. #1
    Join Date
    Jun 2008
    Location
    Australia
    Posts
    399

    Question How to make shell script to run with mouse click?

    Hi,

    I have a shell script file 'program':

    Code:
    #!/bin/sh
    python "./main.pyw"
    it is an executable (I made it an executable from the properties) and I can run it from a console with './program'. But when I double-click on the file nothing happens. I thought that was the whole point making it executable. Otherwise I can type the command itself in a console. Does anyone know how to make it run by clicking the mouse rather than from a console? Thank you.
    Desktop: openSUSE Leap 15 | KDE 5 | Intel i-7500 | Asus ROG STRIX Z270H GAMING | Asus EX-GTX1050TI-O4G nVidia
    Laptop Asus UL30A: openSUSE Leap 15 | KDE 5 | Intel SU7300

  2. #2
    Join Date
    Aug 2008
    Location
    Seattle, WA
    Posts
    1,376

    Default Re: How to make shell script to run with mouse click?

    Try using the full path to 'main.pyw.' The './' will make Python look in the current active directory.

  3. #3
    Join Date
    Jun 2008
    Location
    Australia
    Posts
    399

    Default Re: How to make shell script to run with mouse click?

    The shell script is in the same folder as the python script. But if I use a full path it won't be cross-platform/portable anymore.
    Desktop: openSUSE Leap 15 | KDE 5 | Intel i-7500 | Asus ROG STRIX Z270H GAMING | Asus EX-GTX1050TI-O4G nVidia
    Laptop Asus UL30A: openSUSE Leap 15 | KDE 5 | Intel SU7300

  4. #4
    Join Date
    Aug 2008
    Location
    Seattle, WA
    Posts
    1,376

    Default Re: How to make shell script to run with mouse click?

    Try the full path, just to see if that's causing the problem.

  5. #5
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: How to make shell script to run with mouse click?

    Quote Originally Posted by linuxoidoz View Post
    The shell script is in the same folder as the python script. But if I use a full path it won't be cross-platform/portable anymore.
    The directory where the shell script resides and the current directory at execution time are different things. There are codes you can use in shell scripts to find the directory where it lives and then you can chdir there or to prepend that directory to any filenames.

  6. #6
    Join Date
    Jun 2008
    Location
    Australia
    Posts
    399

    Default Re: How to make shell script to run with mouse click?

    Guys, thank you but I would like a solution not a theory on how it's possible to do things.

    1. I don't want to include full path if it's possible
    2. The shell script will either be in the same folder as the python script or the Python script will at least be in a relative folder
    3. I don't want to write a whole program in another script. What's the point writing a script for a script? I just want to run my Python script by clicking a mouse. Otherwise the user can always run it directly from a console.
    4. There's a Py-exe or something like this in windows to make an executable out of a script. Is there anything like this in Linux?

    Is that possible? Or the only option is what you have already told me - to write a bigger shell script with folder searches and everything? If you have an example, I'd appreciate it, it'll save me a lot of time. Thank you.
    Desktop: openSUSE Leap 15 | KDE 5 | Intel i-7500 | Asus ROG STRIX Z270H GAMING | Asus EX-GTX1050TI-O4G nVidia
    Laptop Asus UL30A: openSUSE Leap 15 | KDE 5 | Intel SU7300

  7. #7
    Join Date
    Jun 2008
    Location
    Queensland, Australia
    Posts
    125

    Default Re: How to make shell script to run with mouse click?

    Is your python app gui or console?

    See how you go if you create a desktop application link...

    Right-click on the desktop -> Create New -> link to application.

    Fill in the details.

    If you need it to run in a terminal, click Advanced Options on the Application tab. Select Run in terminal.

    Paul

  8. #8
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: How to make shell script to run with mouse click?

    You look at $0 of the script. That will either be the full path or a relative path. That will give you the directory the script lives in. By your convention, that will also be where the Python program is.

  9. #9
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    4,654

    Default Re: How to make shell script to run with mouse click?

    I do not really understand why you write a bash script to start a python
    script. It is much more easier to run a python script by making it
    executable the proper way

    Code:
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import sys
    from PyQt4 import Qt
    
    a = Qt.QApplication(sys.argv)
    hello = Qt.QLabel("Hello, World")
    hello.show()
    a.exec_()
    put this into hello.py
    chmod +x hello.py

    and automagically you can start it by clicking from dolphin (or nautilus)



  10. #10
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    4,654

    Default Re: How to make shell script to run with mouse click?

    Martin Helm wrote:
    >
    > and automagically you can start it by clicking from dolphin (or nautilus)


    forgot to add the link

    http://docs.python.org/tutorial/inte...python-scripts



Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •