0

I created executables of a python script (via pyinstaller) for Mac, Windows and Linux. For Linux and Mac, I am running them in the shell since it doesn't have an own interface: just open a shell and type the name of the program.

I am wondering if there is a way to use certain file ending so if the user clicks on the program, it will be automatically executed in the shell or terminal. Alternatively, I would appreciate any other ideas of how to do this.

  • On linux/mac it's not as much about the extension as it is the execute bit. Is your execute bit set? What happens when you double-click it? – PaulProgrammer Apr 02 '13 at 17:30
  • Setting the execute bit is only a necessary condition. How OS's associate a particular file with a particular application (when you click on it in a desktop GUI like the OS X Finder) can be very complicated. For example: http://arstechnica.com/staff/2009/09/metadata-madness/ – Ned Deily Apr 02 '13 at 17:52
  • When i double click it, an open-with window pops up. On mac i can choose to open it in a shell, but not in linux. In linux i can only invoke it from within a shell by typing its name –  Apr 03 '13 at 05:04

2 Answers2

0

The way to do this is not to append a certain file ending, but, as pointed out in the comment, make the file executable (chmod +x <file>) and add the magic bytes to the beginning of the file that tell the system how to execute it.

The magic bytes are #! and are followed by the path to executable. So for a python script you would put something like the following at the top of the file:

#!/usr/bin/env python
Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204
  • Thanks, but i was more looking to a solution that will open and execute an executable in the shell when clicking on it in the file browser. What i basically want to achieve is making a program compiled via pyinstaller from a pyhon script more user friendly –  Apr 03 '13 at 04:58
  • Basically it should ideally work like an exe file on windows; the exe file i created with pyinstaller for windows automatically opens in the terminal –  Apr 03 '13 at 05:00
  • You could try changing the command line to `#!/usr/bin/gnome-terminal` or something like that, but that would only work for shell scripts and not be very portable. – Lars Kotthoff Apr 03 '13 at 09:11
  • Would it be possible to compile the script into an .app file for MacOS that runs in the shell? –  Apr 03 '13 at 14:47
  • 1
    [This question](http://stackoverflow.com/questions/5125907/how-to-run-a-shell-script-in-os-x-by-double-clicking) may be helpful for that. – Lars Kotthoff Apr 03 '13 at 15:14
  • Thank you, Lars, Platypus is a great program to create .app files for MacOS. But now I running into the problem that my program requires the user to make some entries (via raw_input()), the problem is, that the .app does not run in the shell, but for itself. Thus, I get a EOF error when it reaches the raw_input() line. –  Apr 03 '13 at 22:23
  • That's probably a different question to ask. I don't know anything about Platypus. – Lars Kotthoff Apr 04 '13 at 08:14
  • I asked in the other post, I saw that the developer posted an comment there and maybe he will take a look at it. However, the question remains: What about Linux? But I start to think that such a solution does not exist... –  Apr 04 '13 at 22:16
0

Okay, now I finally found out the solution to my question. All you have to do to execute the program upon clicking on it in the file browser is to add the ending .command and make it executable

E.g., exampleprogram.command. Clicking on it will execute the program in the shell

  • I just figured out that this only works for MacOS X, not for Ubuntu, unfortunately –  Apr 08 '13 at 22:13