Hello there,
So I have a situation (trying to work through more general/hypothetical with applications to the ‘real-world version’. The situation let’s say is I have 3 different python scripts written by third parties I would like to employ on my Mac, having them ‘turn on’ at startup and sit in the background and wait for additional commands. To clarify this, I’m trying to say “launch script A” at startup, and do nothing until further commands are received by/given to script A.
In this hypothetical I’m referring to the 3 python scripts Bazarr, DAPS, and Kometa. To me, all 3 should perform this way of launching at start and waiting for further at the very least.
I’ll now try and illustrate how these 3 are launched/invoked/used.
Bazarr - this app has a (semi-usual) wiki on how to get it started with macOS. Specifically, here is the wiki page bazaar wiki detailing how to ‘Autostart on macOS’ according to this group/person. In essence, I create a launchd item with this plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.github.morpheus65535.bazarr</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/python3.8</string>
<string>/Applications/bazarr/bazarr.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/bazarr.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/bazarr.log</string>
</dict>
</plist>
which to my understanding runs the bazarr python script by calling this script against the local python exec the instructions have users install (3.8), which is set to RunAtLoad (to me meaning at startup) and to KeepAlive (to me meaning be ready in background and await further commands. This seems ok generally to me but if you see something odd please illustrate! My question for this one is in the part of the instructions that instruct to create an Automator app to run shell script (loading the plist into launchd) to have something to put in login items…? This doesn’t make sense to me. Isn’t a launchd item set to RunAtLoad essentially a login item? Why do I need something to ‘launch’ a launchd property on start if this is how things are ‘launched’ at start usually?
DAPS - this is basically one large (main) python script which calls a half dozen lesser python scripts with certain details/configuration settings (so they can distribute a suite of scripts that work by putting all personal configuration details into one script to edit). So in theory an either/or to me is: I have to create a launchd plist to call/run each of the lesser scripts in order to run them at scheduled times or I can create one launchd item to call/run the large (main) and keep it alive so that it can run individual scripts on their own individual schedule. I’ve been going with option 2 here i.e. one launchd item to get the main running at start and in background but I’m having trouble theoretically reconciling how this one is any different to the last one (Bazarr). Just trying to figure out/understand generally why 3 python scripts require 3 different launch methods (or so it seems)?
So for this one I have some scheduling info set in the main script and I launch this with a launchd plist of
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.nathan.dapsmain</string>
<key>ProgramArguments</key>
<array>
<string>/Users/nathan/daps_other/myscripts/other/dapsmain.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/stdout.log</string>
<key>StandardOutPath</key>
<string>/tmp/stderr.log</string>
</dict>
</plist>
Which calls my script ‘dapsmain’ which is
#!/bin/bash
cd /Users/Nathan/daps/
source .venv/bin/activate
python3 /Users/nathan/daps/main.py
deactivate
This gets into the whole virtual environment for python script thing that I don’t really understand at all. I kinda get the purpose of using a virtual env for a script (to protect the main os/file/folders from accidents). I kinda get that when manually activating/invoking/deactivating in a Terminal window is when a ‘deactivation’ is required. I’m guessing that’s only somewhat ‘required’ though especially when activating a virtual env for the script’s use in the background - right or wrong? Basically, I’m thinking/wondering if I could just remove the ‘deactivate’ from these sh scripts? Going back to the Bazarr example above, I’m wondering again why the Automator run shell login item?
Kometa - rather than further elongating this now I’d just like to say here Kometa is similar to DAPS in invocation but without the internal scheduling detailed above. So, when I want to run Kometa on schedule I have a launchd plist similar to the DAPS one above but with a CalendarInterval for each call to each function e.g.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.nathan.kometa</string>
<key>ProgramArguments</key>
<array>
<string>/Users/nathan/daps_other/myscripts/other/kr.sh</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>17</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</array>
<key>StandardErrorPath</key>
<string>/tmp/stdout.log</string>
<key>StandardOutPath</key>
<string>/tmp/stderr.log</string>
</dict>
</plist>
But with Kometa I want to run say 3 different functions at 6 different times so I’ve found that I need 3 different launchd plists with their respective times? And the kr.sh script is very similar
#!/bin/bash
cd /Users/Nathan/Kometa/
source kometa-venv/bin/activate
python /Users/nathan/Kometa/kometa.py -r
deactivate
I know this is extra long but I’ve been reading/experimenting for a while now and it just feels like I need to bounce these specifics off of someone who can help me focus learn to be able to apply things more generally later. Thanks for reading!
<?xml version="1.0" encoding="UTF-8"?> Label com.nathan.dapsmain ProgramArguments /Users/nathan/daps_other/myscripts/other/dapsmain.sh RunAtLoad KeepAlive StandardErrorPath /tmp/stdout.log StandardOutPath /tmp/stderr.log Which calls my script 'dapsmain' which is #!/bin/bashcd /Users/nathan/daps/
source .venv/bin/activate
python3 /Users/nathan/daps/main.py
deactivate
This gets into the whole virtual environment for python script thing previously discussed. Just to make sure/try here I believe you said it doesn’t need to be manually ‘deactivated’ in these cases, it’s only needed when invoking manually in Terminal correct? If so, I suppose I should remove this deactivate from my sh script? Going back to the Bazarr example above, I’m wondering again why the Automator run shell login item?
Kometa - rather than further elongating this now I’d just like to say here Kometa is similar to DAPS in invocation but without the internal scheduling detailed above. So, when I want to run Kometa on schedule I have a launchd plist similar to the DAPS one above but with a CalendarInterval for each call to each function e.g.
<?xml version="1.0" encoding="UTF-8"?> Label com.nathan.kometa ProgramArguments /Users/nathan/daps_other/myscripts/other/kr.sh RunAtLoad StartCalendarInterval Hour 17 Minute 0 StandardErrorPath /tmp/stdout.log StandardOutPath /tmp/stderr.logBut with Kometa I want to run say 3 different functions at 6 different times so I’ve found that I need 3 different launchd plists with their respective times? And the kr.sh script is very similar
#!/bin/bash
cd /Users/nathan/Kometa/
source kometa-venv/bin/activate
python /Users/nathan/Kometa/kometa.py -r
deactivate
I know this is extra long but I’ve been reading/experimenting for a while now and it just feels like I need to bounce these specifics off of someone who can help me focus learn to be able to apply things more generally later. Thanks for reading!