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

Click here to return to the 'An AppleScript to obtain the WAN IP address' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to obtain the WAN IP address
Authored by: ozzyrules on Nov 07, '04 10:26:25PM
I modified the script to allow for the choice of email app (Mail or Entourage 2004). This is the first time I have ever touched an AppleScript script so excuse any clumbsiness or mistakes. It does work for me though. Although I am having trouble getting the email choice dialog to come to the front. It stays hidden and the script icon bounces in the dock. Can anyone help?

set response to do shell script "/usr/bin/curl"
set ip_address to extract_ip(response)

set the Reply to display dialog "You IP address is: " & ip_address 
  buttons {"Send by email", "Just leave in pasteboard"} 
  default button "Just leave in pasteboard" giving up after 10 with icon stop

-- Leave the ip address in the Finder's pasteboard so it is accesible
tell application "Finder"
  set the clipboard to ip_address
end tell

-- Send en email if requested
set mailto_addr to ""

if button returned of Reply is "Send by email" then
  send_ipget_mail_message(mailto_addr, ip_address)
end if

on send_ipget_mail_message(email_addr, ip_address)
  -- choose email application
  set the answer to display dialog 
    "Which Email application do you use?" buttons {"Mail", "Entourage 2004"} 
    default button "Mail" giving up after 10 with icon stop
  -- Entourage choice
  if button returned of answer is "Entourage 2004" then
    tell application "Microsoft Entourage"
      set theAccount to IMAP account "David"
      set theRecips to {address:{display name:"David", address:""}, recipient type:to recipient}
      set newMessage to make outgoing message at out box folder with properties {account:theAccount, subject:"test", content:ip_address, recipient:theRecips}
    end tell
    -- Mail choice
    tell application "Mail"
      set composedMessage to (a reference to (make new outgoing message 
        at the beginning of outgoing messages))
      tell composedMessage
        make new to recipient at beginning of to recipients 
          with properties {address:""}
        set the subject to "iPGet report"
        set the content to ip_address
      end tell
      send composedMessage
    end tell
  end if
end send_ipget_mail_message

-- Function to extract ip from HTML returned by 
on extract_ip(this_text)
  set clean_ip to ""
  set this_char to ""
  repeat with this_char in this_text
    set this_char to the contents of this_char
    if the this_char is in {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."} then
      set the clean_ip to the clean_ip & this_char as string
    end if
  end repeat
  return the clean_ip
end extract_ip

-- end script

[ Reply to This | # ]