当我连接到WiFi网络时,我正在使用AppleScript输出我机器的IP地址。
在Bash脚本中,我使用了以下命令:
ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2
但当我在AppleScript中使用相同的命令时,它会给我一个错误。
以下是AppleScript:
tell application "Terminal"
activate
set IPAddr to do shell script "ifconfig | grep \"inet\" | grep -v 127.0.0.1 | cut -d\ -f2"
display dialog IPAddr
end tell
结果显示:
error "Terminal got an error: User canceled." number -128
我假设问题是我在terminal命令中使用的反斜杠。
我怎样才能解决这个问题?
非常感谢!
干杯