October 11, 2013 · all, software, programming

How to use launchd to copy a dynamic IP address to your Dropbox folder

Since they won't give me a static IP address here I made this little MacOS Launch Agent to copy my current IP address to my Dropbox folder so I can make sure to access it from anywhere. This version runs at boot-up and once per day.




Label
local.ipaddress
ProgramArguments

/usr/sbin/ipconfig
getifaddr
en0

StandardOutPath
/DROPBOXDIRECTORY/ipaddress
StartInterval
86400
RunAtLoad



Save it to ~/Library/LaunchAgents/local.ipaddress and make it executable (required?) by doing chmod +x ~/Library/LaunchAgents/local.ipaddress

Then activate it:

launchctl load ~/Library/LaunchAgents/local.ipaddress
launchctl start ~/Library/LaunchAgents/local.ipaddress

If you want to give it root privileges you can make it run every time the DCHP lease changes by adding:


UserName
root
WatchPaths

/private/var/db/dhcpclient/leases/

← All posts