使用脚本MacOS切换网络

时间:2018-04-14 06:30:05

标签: macos

OSX中是否还有编写切换网络首选项的脚本? I.E.从以太网切换到wifi再返回。

我熟悉在Windows中编写批处理文件但在MacOS中编写

1 个答案:

答案 0 :(得分:0)

可能最简单的方法是已经定义了位置,然后执行以下操作:

#!/bin/sh

if [[ $# -eq 0 ]] ; then
    echo "No arguments, try one of this:"; networksetup -listlocations
    echo "Current location: "; networksetup -getcurrentlocation
    exit 1
fi

eval networksetup -switchtolocation \"$@"\

如果网络位置已成功更改,则会打印found it!