Skip to content

Instantly share code, notes, and snippets.

@gregoryvit
Created July 20, 2020 21:34
Show Gist options
  • Save gregoryvit/19a15c7b363c31e61e402ee2df9e38b4 to your computer and use it in GitHub Desktop.
Save gregoryvit/19a15c7b363c31e61e402ee2df9e38b4 to your computer and use it in GitHub Desktop.
Makefile to simplify launchd scripts generation

Makefile to simplify launchd scripts generation

Makefile commands

  • make install – install launchd.plist file from local directory to system with value of SCRIPTID
  • make uninstall – uninstall launchd config from system by value of SCRIPTID variable
  • make log – prints content of error log file
  • make show – print line with current script based on launchctl list command
  • make run – start launchctl script
  • make plist – generates new local launchd.plist file. All configurations and template you can setup in Makefile
SCRIPTID=my.awesome.script.identifier
ERRORLOGPATH=${HOME}/launchd.${SCRIPTID}.stderr.log
HOURS=9
MINUTES=0
SCRIPT_TO_RUN_PATH=`pwd`/run.sh
install:
cp ./launchd.plist ~/Library/LaunchAgents/${SCRIPTID}.plist
launchctl load ~/Library/LaunchAgents/${SCRIPTID}.plist
uninstall:
launchctl unload ~/Library/LaunchAgents/${SCRIPTID}.plist
rm ~/Library/LaunchAgents/${SCRIPTID}.plist
log:
cat ${ERRORLOGPATH}
show:
launchctl list | grep ${SCRIPTID}
run:
launchctl start ${SCRIPTID}
plist:
echo "<?xml version="1.0" encoding="UTF-8"?>" \
"\n""<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">" \
"\n""<plist version="1.0">" \
"\n"" <dict>" \
"\n"" <key>Label</key>" \
"\n"" <string>${SCRIPTID}</string>" \
"\n"" <key>Program</key>" \
"\n"" <string>${SCRIPT_TO_RUN_PATH}</string>" \
"\n"" <key>StartCalendarInterval</key>" \
"\n"" <dict>" \
"\n"" <key>Hour</key>" \
"\n"" <integer>${HOURS}</integer>" \
"\n"" <key>Minute</key>" \
"\n"" <integer>${MINUTES}</integer>" \
"\n"" </dict>" \
"\n"" <key>StandardErrorPath</key>" \
"\n"" <string>${ERRORLOGPATH}</string>" \
"\n"" </dict>" \
"\n""</plist>" \
> launchd.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment