I am looking for a way to initiate a PPP connection with my EVDO modem from the command line instead of having to go to System Preferences -> Network and hit "Connect".
3 Answers
To connect a network device, use the System Events
dictionary:
tell application "System Events"
tell current location of network preferences
connect service "Sprint 3G"
end tell
end tell
assuming the name of the service is Sprint 3G
:
To disconnect, change connect
to disconnect
:
tell application "System Events"
tell current location of network preferences
disconnect service "Sprint 3G"
end tell
end tell
Once you've saved your scripts with names, you can use the terminal open
command to kick off either script.
-
Well done! I hope you don't mind me adding an open command to finish this off in the terminal way.– bmike ♦Aug 31, 2011 at 5:06
-
-
Here's what a screenshot of the Alfred integration looks like: img.skitch.com/20110831-pg1nht8jbnb46nwgx27saw2uxc.png– ericAug 31, 2011 at 5:19
-
How do you call Alfred from the command line? Perhaps you just meant to script it in response to a shortcut key.– bmike ♦Aug 31, 2011 at 13:53
-
Yes, I just mean that I was able to use the script in response to a keyword in Alfred.– ericSep 1, 2011 at 7:06
I'm sure there is a more elegant way, but this could be done with UI scripting. I don't have an EVDO modem, so I can't give the specifics of the script that would work, but first you would go to -> System Preferences -> Universal Access and make sure "Enable access for assistive devices" is checked.
Then, you could write a script using a text editor. As I said, the specifics of the script would depend on your system and the layout of the screen you're trying to control, but it would look something like this:
#!/usr/bin/osascript
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.network"
click button 1
tell application "System Preferences" to quit
You'd save the script, make it executable, and then you could enable your modem from the command line. I'm sure there's a more elegant way that doesn't involve popping up a window and that doesn't involve so much trial and error at the "click button 1" stage, but this is a start.
-
I would really like to find a way to do it without needing to actually open the System Preferences.– ericAug 30, 2011 at 4:03
-
Of course. As I said, my approach is distinctly inelegant, but still scriptable. I'd love to see a better answer, and I suspect something involving pppd is more likely to be viable, but I have less advice to offer on that front.– Daniel ♦Aug 30, 2011 at 4:40
I think this can be done using pppd. You'll need to find the device name (/dev/tty...) and read through the long list of available options but it looks like that could work.
-
I don't have a modem anymore to test this unfortunately, but I have used it in the past. (This is exactly what's used for modem connections in linux, for example.) If this answer is "negatively helpful" I would appreciate learning why it was downvoted with a comment. Sep 7, 2011 at 2:42
opensnoop
, the otherfs_usage
(without your modem, it's hard to guess where your scripts are stored)