Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Copy public IP address to clipboard via keyboard shortcut Network
A friend asked me for a way to put his current public IP address (which changes regularly, it seems) on the clipboard via a keyboard shortcut, and to alert him as to what value was copied. Using a combination of a shell script, Butler, and Growl (specifically, the shell command growlnotify), I was able to put together a solution for him. Note that Butler (disclaimer: I'm part of Many Tricks, Butler's developers) can be replaced by any program that lets you execute shell scripts via a hot key. You could also put the shell script in Automator, and go that route ... but I digress.

Here's the script:
MYIP=`curl -s '' | sed 's/.*Current IP Address: \([0-9\.\.]*\).*/\1/g'`
echo $MYIP | pbcopy
/usr/local/bin/growlnotify 'IP address copied' -m "Address was: $MYIP"
I made this executable and saved it as copyip. The MYIP line was culled from some combination of old hints and comments here; I wasn't able to figure out exactly where I pulled it from, though. It basically uses curl to grab the "What's my IP address?" page from, then uses sed to process out the actual IP number. The second line puts the IP address onto the clipboard, courtesy of pbcopy. Finally, the last line calls growlnotify to display an onscreen notification; the full path was used as I found it required for the next bit).

The last step was to assign this script to a hot key. To do that, I used Butler's ability to run AppleScript code. From the plus-sign icon at the bottom of the Butler window, I chose Smart Item » AppleScript » AppleScript. In the Source Code section of the new Smart Item, I put this:
do shell script /path/to/copyip
In the Triggers tab, I assigned a keyboard shortcut, and I was done. My friend can now have his public IP placed on the clipboard with a simple keyboard shortcut, and get a visual confirmation that it was done correctly. Note that there's no error handling of any sort in my script; if it fails, it's going to fail ugly. You have been warned.

[crarko adds: I haven't tested this one.]
  • Currently 3.67 / 5
  You rated: 1 / 5 (6 votes cast)

Copy public IP address to clipboard via keyboard shortcut | 3 comments | Create New Account
Click here to return to the 'Copy public IP address to clipboard via keyboard shortcut' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Copy public IP address to clipboard via keyboard shortcut
Authored by: Sesquipedalian on Jan 20, '11 09:35:37AM
Rather than
MYIP=`curl -s '' | sed 's/.*Current IP Address: \([0-9\.\.]*\).*/\1/g'`
you could instead use
MYIP=`curl ''`
This option returns an html document whose only content is the IP number (not even an <html> tag is included), so there is no need to parse it at all. This allows you to skip the invocation of sed.

[ Reply to This | # ]
Copy public IP address to clipboard via keyboard shortcut
Authored by: robg on Jan 20, '11 01:06:42PM
Nice change; I've been using the checkip site for so many years I just copy and paste the same line over and over.

Partner at Many Tricks, maker of useful apps
Edited on Jan 20, '11 01:08:13PM by robg

[ Reply to This | # ]
Copy public IP address to clipboard via keyboard shortcut
Authored by: egon1024 on Jan 22, '11 04:15:16AM

If all you want is a growl notification, you could just get a free DynDNS account and set up the Mac client. It will do a growl notification any time your IP changes, doesn't require a keyboard shortcut to check, and gives you the added benefit of updating a hostname to point at you.

[ Reply to This | # ]