Skip to content

Commit

Permalink
Change LaunchD style from KeepAlive to WatchPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Sep 25, 2018
1 parent f2d3fd2 commit 18aafe9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
12 changes: 4 additions & 8 deletions pkg/com.sheagcraig.yo.on_demand.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
<string>/usr/local/bin/yo_scheduler</string>
<string>--cached</string>
</array>
<key>KeepAlive</key>
<dict>
<key>PathState</key>
<dict>
<key>/private/tmp/.com.sheagcraig.yo.on_demand.launchd</key>
<true/>
</dict>
</dict>
<key>WatchPaths</key>
<array>
<string>/var/run/com.sheagcraig.yo.on_demand.launchd</string>
</array>
</dict>
</plist>
13 changes: 13 additions & 0 deletions pkg/postinstall
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/bin/bash

[[ $3 != "/" ]] && exit 0

# Rename yo.sh to yo so we can call it like a regular cli utility.
mv /usr/local/bin/yo_scheduler.py /usr/local/bin/yo_scheduler

# Load our launch agemts in the background for the logged in user
CONSOLE_UID=`/usr/bin/stat -f%u /dev/console`
if [ $CONSOLE_UID -gt 499 ]; then
/bin/launchctl asuser $CONSOLE_UID \
/bin/launchctl load -w \
/Library/LaunchAgents/com.sheagcraig.yo.login_once.plist
/bin/launchctl asuser $CONSOLE_UID \
/bin/launchctl load -w \
/Library/LaunchAgents/com.sheagcraig.yo.on_demand.plist
fi
5 changes: 5 additions & 0 deletions pkg/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
rm -rf /Applications/Utilities/yo.app
rm -rf /Applications/Utilities/yo
rm -rf /Applications/Utilities/yo.localized

WATCH_PATH="$3/var/run/com.sheagcraig.yo.on_demand.launchd"

touch "$WATCH_PATH"
chmod a+w "$WATCH_PATH"
6 changes: 3 additions & 3 deletions pkg/yo_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

__version__ = "2.0.0"
BUNDLE_ID = "com.sheagcraig.yo"
WATCH_PATH = "/private/tmp/.com.sheagcraig.yo.on_demand.launchd"
WATCH_PATH = "/var/run/com.sheagcraig.yo.on_demand.launchd"
YO_BINARY = "/Applications/Utilities/yo.app/Contents/MacOS/yo"
# This is captured straight from running the Yo binary and must be
# updated manually.
Expand Down Expand Up @@ -283,8 +283,8 @@ def touch_watch_path(path):
with open(path, "w") as ofile:
ofile.write("Yo!")
# Give the LaunchDaemon a chance to work before cleaning up.
time.sleep(5)
os.remove(path)
# time.sleep(5)
# os.remove(path)


def exit_if_not_root():
Expand Down

0 comments on commit 18aafe9

Please sign in to comment.