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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for mac_agents-2018.12.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c0b240dac7ffabad76dfd1d9e896f6bb4f1b82263782d551908b89a09c6ba43 |
|
MD5 | 9da9684288071c1ec0fa89fe5f5d4dd2 |
|
BLAKE2b-256 | 29f1fb914bd3c31732d2abee15871617535ecfed3a2f85fbf27726f32613faa1 |