Reputation: 227
I have a python file that I want to run every time the mac comes out of its sleep. I have turned the .py file into an dmg file and placed into login items section of the mac this is in settings -> users -> login items. My problem is that this seems to only run the DMG file when i fully logout of the the mac. I always just click the sleep option on the mac. Is there a way to run the python script each time the computer wakes up from a sleep?
Upvotes: 1
Views: 1218
Reputation: 53
@kitchen800 you can try making a shell script that runs your python program, or like another suggestion, use pyinstaller/py2app to make it into a executable application. Putting the python program itself in the Open at login will simply open the python script, not run it.
runpyscript.sh
(the file name doesn't matter, but keep the .sh)python3 path/to/file.py
chmod +x path/to/runpyscript.sh
.sh
at the end of the file to make it executable by double-clickingpip install pyinstaller
(if you haven't installed pyinstaller already)pyinstaller path/to/file --onefile <other options go here>
dist
. There, you should find a file_name_here.app
and you can put it in Open at login.pip install py2app
cd path/to/file
.setup.py
file for your python application. In the command prompt, write py2applet --make-setup file_name_here.py
python3 setup.py py2app -A
to construct the app in alias mode. In the same directory, go to the folder called dist
in Finder and open it. You should find a .app
file in it. If anything goes wrong while opening the .app
file, then configure setup.py
and run rm -rf build dist
and the above setup.py
command again until it works.python3 setup.py py2app
to build the final version of the app.Upvotes: 2