Overview -Use py2app to convert a program created in python into an app. -Target console-based programs, not GUI applications that use wxPython or pyQt. -When you start the created app, terminal will start up and the program will run on it.
This time, I wanted to distribute the python CUI application as shown below to the general public, and tried to create an application for mac. However, even if I execute the created app, there is no sign that it will start at all (it has been bound in the Dock all the time) ... In fact, the program is ** running in the background **. However, since the execution status is refreshing as it is, I want terminal to appear and execute on it. (By the way, py2exe for windows works well as shown in the figure below ...) The goal this time is to create an application that works ** "on the console" ** of a CUI application created with python, just as it was created with py2exe.
sudo pip install py2app
Next, create setup.py to convert the python code (let's call it base.py) into an app.
py2applet --make-setup base.py
Then, based on this setup.py, make base.py into an app with py2app.
python setup.py py2app
I think this will create base.app.
(Even if the app created at this stage is executed, it will not be executed in ** Terminal **.)When I double-click base.app, nothing happens on the screen (it is bound in the Dock or does not respond). しかし,base.app/Contents/MacOS/baseをダブルクリックするとterminalが起動し,その上でプログラムが動作しているかと思います! This time ** I will create a script that directly hits this executable file and make it an app ** (let's call it wrap.app). The script uses AppleScript. As will be described later, it is easy to get the path of the resource folder in the app file with AppleScript, so AppleScript is recommended as the script to create. Write the following script.
wrapper.scpt
set base_path to (POSIX path of (path to resource "base.app/Contents/MacOS/base")) as string
tell application "Terminal"
activate
do script (base_path & " &")
end tell
On the first line path to resource" base.app / ... "
** Get the absolute path of "base.app / ..." in the resource folder of the app where this script is executed * *. Since the acquired path is an alias reference, convert it to POSIX format and store the converted string type in base_path.
Start Terminal with tell application" Terminal "
and activate it. Terminal will now be displayed on the screen. Then execute the executable file in base.app. At this time, adding &
to the end will result in background operation, and ** the program will be executed even if this script ends ** (conversely, if you do not add &
, the program must end on Terminal. wrap.app does not end either.)
Create wrap.app based on wrapper.scpt created above.
This operation is very easy. Just do the following on the Terminal:
$ osacompile -o wrap.app wrapper.scpt
This will create wrap.app.
Finally, store the base.app of the app you want to run on the console created in 1. in the resource folder in wrap.app.
$ cp base.app wrap.app/Contents/Resources/base.app
http://qiita.com/mattintosh4/items/83e1540c31c803c3fd5e http://qiita.com/mattintosh4/items/3220a75ae6229553b87b