2011-02-16 61 views
2

即时通讯使用mac和脚本编辑器或automator,我想运行一个应用程序时,我自动连接到特定的IP地址我一直在尝试脚本编辑器:ip地址更改=启动一个certian应用程序

if IP address is changed to "192.168.2.102" or "192.168.2.103" 

tell application "app" activate end tell 

但它仍然需要更多从我... 我可能没有接近,但我没有这方面的经验。

回答

1

您可以使用on idle使您的脚本在后台运行。以下面的例子:

global ipValue 

on idle 
    set newIpValue to do shell script "curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z/<> :]//g'" as string 

    if not (newIpValue = ipValue) then 
     -- perform your action 
    end if 

    return 10 -- time in seconds to perform checking 
end idle 

而且,你必须标记上停留的AppleScript的开放保存脚本作为应用程序时,保存对话框。

我不确定你想要哪个IP,但这个例子从http://checkip.dyndns.org得到你的网络IP。

+0

哎感谢这么多回答,我希望得到它来激活这两个IP地址的应用程序,所以我只需将IP地址放在“(newIpValue = ipValue)”并指定应用程序运行? – mark 2011-02-16 20:37:08