Search code examples
pythonmacospy2app

Add py2app application to OSX login items


I've created a very simple script that parses a webpage, finds an image, and downloads it to the machine. This script also checks every 5 minutes to see if the picture has changed, and if it has, it downloads the new one. So far, I've been successful in making this a standalone py2app, and it works fine. I can run it, and it does its thing. I have a few questions:

This app would probably be best served as a background application. I can specify that in my py2app setup.py using LSBackgroundOnly=True as follows:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['downloader.py']
DATA_FILES = []
plist = dict(LSBackgroundOnly=True)
OPTIONS = {'argv_emulation': True, 'plist': plist}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Now. What I'd really like to do now is add this app to the mac login items. Is there any way to do this in py2app? I wasn't able to find anything in the documentation. I did, however, find in the Apple developer documentation how to do this with a regular Obj-C app. Adding Login Items

However, my Objective C knowledge is limited at best, so I struggled to come up with a good solution for this. Thanks in advance for any help.


Solution

  • I'm not familiar with py2app, but if it makes an application bundle, the process is simple.

    Just run this in Terminal:

    sudo defaults write \
        /Library/Preferences/loginwindow \
        AutoLaunchedApplicationDictionary -array-add \
        '{ Path="/Applications/YourApp.app"; }'
    

    Substitute the name and path where your application is installed.