I wanted to make a shell script that connects to a hidden wireless network on my macbook pro by creating a network. However, I only want to connect to that network when I want to and to prevent airport from connecting automatically I'll have to delete the network's password from keychain.我想制作一个 shell 脚本,通过创建网络连接到我的 macbook pro 上的隐藏无线网络。但是,我只想在需要时连接到该网络,并且为了防止机场自动连接,我必须从钥匙串中删除网络密码。
Im also aware that in OSX 10.7 the security command can modify the keychain.我还知道在 OSX 10.7 中,该security命令可以修改钥匙串。
Anyway I would appreciate any help someone can give me. I'm also willing to use applescript or something else if it works. Thank you.无论如何,我将不胜感激有人能给我的任何帮助。如果可以的话,我也愿意使用 applescript 或其他东西。谢谢。
sudo was needed because this keychain is located in the systems library. security also contains a lot more delete and useful commands and you can specify how you want to indicate the location in this command.需要 sudo,因为此钥匙串位于系统库中。security还包含更多删除和有用的命令,您可以指定如何在此命令中指示位置。
edit: I was having some trouble using this command and went back and learned I could use another command to not remember the network at all which I would have used before if I had found it. With this option you can do a wealth of things with your adapter along with the networksetup option.编辑:我在使用这个命令时遇到了一些麻烦,然后回去了解到我可以使用另一个命令来完全不记得网络,如果我找到它,我以前会使用它。使用此选项,您可以使用适配器以及 networksetup 选项执行大量操作。
Here is my final script which first runs as root. then it changes the system preferences to not remember new networks. Then it disconnects from any current networks. Then it adds the new network. Lastly, it makes the system remember new wifi networks.这是我的最终脚本,它首先以 root 身份运行。然后,它会更改系统首选项以不记得新网络。然后,它会断开与任何当前网络的连接。然后,它会添加新网络。最后,它使系统记住新的wifi网络。