The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...' --Isaac Asimov
That's Funny… random header image

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

October 11th, 2013 by eric

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.

<?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>local.ipaddress</string>
 <key>ProgramArguments</key>
 <array>
  <string>/usr/sbin/ipconfig</string>
  <string>getifaddr</string>
  <string>en0</string>
 </array>
 <key>StandardOutPath</key>
  <string>/DROPBOXDIRECTORY/ipaddress</string>
 <key>StartInterval</key>
  <integer>86400</integer>
 <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

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:

 <key>UserName</key>
  <string>root</string>
 <key>WatchPaths</key>
  <array>
   <string>/private/var/db/dhcpclient/leases/</string>
  </array>

Tags:   · No Comments

Leave A Comment

0 responses so far ↓

  • There are no comments yet...add one by filling out the form below.