Skip to main content

LaunchAgents + python

Project description

Install

$ [sudo] pip install mac-agents

Classes

mac_agents.Agent - launchd.plist generator

method __doc__
create() create launchd.plist file and StandardOutPath, StandardErrorPath logs
load() launchctl load plist file
read() return a dictionary with plist file data
rm() remove plist file (if exist)
unload() launchctl unload plist file
update(**kwargs) update plist file data
write(data) write a dictionary to a plist file
@property __doc__
Label path.to.file.py
ProgramArguments ['bash','-l','-c','python $script $plist']
StandardErrorPath ~/Library/Logs/LaunchAgents/$Label/err.log
StandardOutPath ~/Library/Logs/LaunchAgents/$Label/out.log
WorkingDirectory script file dirname
path plist path - file.py.plist
script script path - class module file

Functions

function __doc__
mac_agents.agents(path='~/Library/LaunchAgents') return list with launchd.plist files for .py scripts
mac_agents.create(path) create launchd.plist from python file and return path
mac_agents.jobs() return list with launchctl jobs (pid, status, label)
mac_agents.scripts(path='~/Library/LaunchAgents') return list with *.py files
mac_agents.tag(path='~/Library/LaunchAgents') set Finder tags. red - status, orange - stderr, gray - unloaded

CLI

usage __doc__
python -m mac_agents.create path ... generate launchd.plist from python file(s)
python -m mac_agents.tag [path] set Finder tags. red - status, orange - stderr, gray - unloaded

Examples

~/Library/LaunchAgents/file.py

import mac_agents

class Agent(mac_agents.Agent):
    StartInterval = 5

    def run(self):
        pass

if __name__ == "__main__":
    Agent().run()
>>> Agent().create().load()
>>> Agent().unload().rm()
$ cd ~/Library/LaunchAgents
$ find . -name "*.py" | xargs python -m mac_agents.create "$@"
$ find ~/Library/LaunchAgents -name "*.plist" | xargs launchctl load
$ launchctl list | grep .py$
$ find ~/Library/LaunchAgents -name "*.plist" | xargs launchctl unload
$ launchctl list | grep .py$ | awk '{print $3}' | xargs -I '{}' launchctl remove {}
$ find ~/Library/LaunchAgents -type f -name "*.py.plist" -exec rm {} +

Links

readme-md - README.md generator

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mac-agents-2018.12.1.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

mac_agents-2018.12.1-py2.py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page