Made OSX .sh file into .app, refuses to execute - python

To preface, I've read other threads on the topic, but all their solutions don't work for me.
I have a small .sh file that just runs python3 foo.py. I used a script to turn this file into a .app file, but when I try to open it, I can see the app begin to appear in the dock and then disappear. However, when I open the file inside of the Unix executable itself in Terminal, all is well.
I have tried:
Changing the shebang in the .sh file to both #!/usr/bin and #!/urs/bin/env
Creating an empty .plist file
Making sure every file has execute permissions
Oddly enough, running open appname.app gives the following:
LSOpenURLsWithRole() failed with error -10810 for the file /Users/blah/blah/Lofi.app.
Thanks in advance

When you say you've read other threads on the topic, and the solutions don't work, does that mean you tried every thing in the comments under the sh-to-app script? There are a couple of specific fixes enumerated there.
What OS are using? Looks like higher OS needs you to register the app with the OS.
Check permissions of your personal shell script
Does it open in Terminal with open APP.app? I think you're saying it does. You can look at the last comment under the the sh-to-app script for possibly helpful instructions.

Not so much an answer, more of a workaround. I ended up taking the APP.app/Contents/MacOS/APP executable and creating an application in Automator that simply runs the file, and saving that process as an application in the Applications folder.

Related

How do force or change my terminal to run python executable file in python 3 just by opening the file?

My terminal is running python 2 so when I run my python file the program fails.
So basically I am new to programming and trying to create a small python script to help me auto create folders. I also want to give the script to colleges so that they can use it on their systems too.
I know that I can run my file in terminal by using "python3 myfile.py" and it will work, but that's too much off a mission to do for my colleges and as my colleges are not familiar with code or terminal for that matter, I wanted to create an executable file so that they just click to open type a few answers to the promoted question and boom folders created.
This is where I run into a problem, I have "#!/usr/bin/env python3" at the top of my file but when I run the script IDLE opens up and it just shows the code I have written but doesn't seem to run the actual script I wrote. Am I doing something wrong?
I also then though perhaps I could just use the terminal to run the file as it is now executable, so I go into terminal and enter "myfile.py" and the program runs but in python 2 so my script fails as it is in python3. So another question would be is there a way to code into my python file, when running this file make sure you use python3? as I would want this to work on all colleges system without them having to write out anything in terminal?
Sorry for the long explanation but any advice would be greatly appreciated.
Thank you in advance
When you are on windows you can just create a .bat file where you write: python3 myfile.py in it.
Both files have to be in the same directory.
If you want to have a .exe you can also use py2exe.
You could also try just #!/usr/bin/python3 without env.
More here.

The system cannot find the file specified using subprocess Popen and only works on desktop with simple bat files

In Idle I am getting the error:
FileNotFoundError: [WinError 2] The system cannot find the file specified
While trying to open a file in a folder on my desktop.
p = Popen("open.bat", cwd=r"C:\Users\MSI\Desktop\Project")
stdout, stderr = p.communicate()
Is the lines that are opening the file.
One thing to note, this works if I have a simple batch file on my desktop that just echos a word but doesn't for another batch doing other stuff in my project folder. If I put the simple batch file in my project folder it also does not work. I am POSITIVE I have the right path because I copy and paste it from the properties window. I also tried to make a shortcut of the bat file but noticed that it's path is the same as the original.
I want the script to run the file, so if there is anything that I should change, please let me know.
PS: Running on Python 3.7
I finally fixed this by ditching subprocess for os
os.chdir(r"path")
os.startfile(r"file.bat")
still not sure why subprocess was having trouble with the same exact task. Anyways, I advise using this since so far it has worked every time

Rundeck :: Execute a python script

I am new to Rundeck, so I apologize if I ask a question that probably has an obvious answer I'm overlooking.
I've installed Rundeck on my Windows PC. I've got a couple of Python scripts that I want to execute via Rundeck.
The scripts run fine when I execute them manually.
I created a job in Rundeck, created a single step (script file option) to test the python script.
The job failed after six seconds. When I checked the log, it was because it was executing it line by line rather than letting python run it as an entire script.
How do I fix this?
You had to put:
#!/usr/bin/python
or similar, with location to your python binary, as 1st line. To indicate which interpreter to use for whole file.
okay, so I changed the step type to a command rather than script file and it worked.
I guess my understanding of what a script file is was off.

OSX: Creating an automator workflow with Python makes the workflow invalid

I'm making a chat client for OSX, and I wanted it to be able to run as both a .app (for my less technologically inclined users) and as a .py file. I made a workflow app that contained two .py files (an auto-updater and the client itself), run by a python script in the .wflow file. This worked well. However, I couldn't update the updater or workflow script, and the icon was the Python rocket instead of the icon I had chosen. Then, I combined the client .py file with the updater .py file. This still worked, and now I could update the updater. I still couldn't update the python script in the workflow, though, and the icon was still wrong. So, I modified the updater to open the .wflow file, split it into a list (based on python comments in the workflow's python script, such as "#Start") of the stuff before the script, the script's modification time, and the stuff after the script. If the modification time isn't the same as the modification time of the remote file (the one that the updater updates from), then the script downloads the remote .py file, replaces characters (<, >, &) that .wflow files replace ('<' -> "<"), and opens document.wflow with the "w" (write/replace) flag. Then, the stuff that was before the old script, the downloaded script, and the stuff that was after the old script (using file.write(''.join(list))) are all put into document.wflow. This should work, but OSX no longer sees document as an automator file.
As you can see, OSX thinks that the old file is a Workflow, while the new file is a "Microsoft Excel 97-2004 workbook". The IMClient.app (the application that contains document.wflow) gives this message when I try to run it: "The document "IMClient" could not be opened because it is damaged or incomplete." Does anyone know how to fix this?
I'm using python 2.7 and OSX 10.7. The updater is downloading files via FTP.
If clarification is necessary, just ask. I'll post the working and nonworking files if anyone wants them.
EDIT: the file command gives "document.wflow: XML document text" for both the old and new file.

Python: Errors reading/writing file from python executable

I'm writing a Python application that is executable. It reads and writes to a file. The application uses wx for a GUI and has been given the following permissions:
chmod +x app.py
When I load the application from the terminal like so:
./app.py
The application loads and causes no errors.
However, when I double click the app.py file and click 'execute', everything works perfectly except for the reading and writing of this file. This is a major part of the program and causes errors.
I cannot, for the life of me, understand why this is not working.
I have attempted to set it so that it loads as the root user each time with no luck. I have also been developing as the root user the entire time, so I shouldn't see any issues.
I am using the default Raspbian OS.
It sounds like you need to modify the permissions of the file to be readable/writable/executable by the user you log into the GUI with. Do some reading on Linux File Permissions and see where that takes you.

Categories

Resources