IP address VIA e-mail

Hey folks,

I’ve had a mac for some time now, but I am just starting to see the benefits of applescript (I know!). I’ve picked up a few things and can’t wrap my head round others.

From work, I’ll occasionally VNC back to my mac to check up on things. The problem is that I don’t have a static IP address.

Is there any way, through applescript, that I can get OS X to grab my external IP address and attach that to an e-mail?

I’ve already tried a script where I send an e-mail with specific rules that tells the mac to take a screenshot and return that to me. It works well, so I’m fine with setting up rules and all that.

Any tips?

I’ve looked around and I’ve not seen anything along these lines in the archive, so I apologise if this has already been asked.

Many thanks.


try this, it sends the IP address in the subject

property theName : "John Doe"
property theAddress : "john@doe.com"

set ipAddress to do shell script "/usr/bin/curl http://checkip.dyndns.org | /usr/bin/awk '/: / {print $6}' | /usr/bin/cut -f 1 -d '<' "

tell application "Mail"
	set newMessage to make new outgoing message with properties {visible:true, subject:ipAddress}
	tell newMessage
		make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
	end tell
end tell

Nice. I’ve been using this for many years now:

set Ext_IP to word 25 of (do shell script "curl checkip.dyndns.org")

The trick, of course, is to detect that your ip address has changed, so I’d be inclined to run a stay-open on idle script that checked periodically and emailed me if there was a change. (I don’t do this myself – I use Yazsoft’s ShareTool which monitors my IP address and sends me a gMail if it changes).

You could also use dydns, which allows you to use a url instead of an ip address.


Thank you, Stefan. You’re a hero.

It did everything but send the e-mail, so I put activate and send before end tell and it sent.

@Adam - I’ll look in to that. Thank you for the scriplet.

@cwtnospam - I’ve used that for other things before. The reason I don’t use it is because I don’t like the idea of a static address leading back to my home computer. I’ve done it for servers, but I just wouldn’t want to risk anything.

Thank you all for the help and guidance. (:

Edit: Looking at it now, it’s not working fully. If I run the script from the file, it’ll grap the IP attach it to the subject line then send it, but if I input the e-mail rules and send an e-mail requesting the IP, the script doesn’t run. I tried the screenshot script under the same rule and it works fine.

Any ideas as to why it isn’t working?

No immediate idea of why it’s not working, but a very neat idea to key it off an email you send home to trigger a mail rule. Be sure to let us know if you solve that yourself. :slight_smile:

In Leopard sending a mail from a rule doesn’t work any more. Don’t ask, why