Q:Apple Script:How 获取IP地址

Q:Apple Script:How to get IP address

我是 apple script 的初学者,一直在尝试让 apple script 检查计算机是否连接到互联网。我试过:

  1. tell application "system events" get IPv4 address

  2. system info IPv4 address

没用:/

试试这个……这应该适合你

try
    set theIP to do shell script "curl ifconfig.co"

    set the clipboard to theIP

    activate
    display dialog "Your Current IP Address Is.." & linefeed & theIP & linefeed ¬
        & "It Has Been Copied To Your Clipboard" with icon 2 buttons ¬
        "OK" default button 1 with title "Your Current IP Address Is.." giving up after 10
on error 
    display dialog "You Have No Internet Connection" buttons {"Cancel", "OK"} default button "OK"
end try