I'm new here. And I need help on applescript.
Currently i'm using USB Modem to connect to internet, it's an everyday routine so i can work. But i want to make it run automaticaly when i plugged the USB modem to my MBP, and run script to connect internet with using configuration that already set.
Here is the script that i use to connect to Internet.
tell application "System Events"
tell current location of network preferences
set modem to service "Flexi EVDO"
set isConnected to connected of current configuration of modem
if isConnected then
disconnect modem
else
connect modem
end if
end tell
end tell
I ran this script using automator and save it as App.
What i want to achieve is if i can run this script directly when i plugged my USB Modem. I'm stuck at detecting the modem script. I have no idea about this.
Can anyone help me? Thanks in advance. Really appreciated every comments. Sorry for my bad english.
Thanks! again. :)
Your english is very good so don't worry about that. The first thing to do it to figure out if you can detect if the modem is plugged-in. We can use the system profiler for this. Plug in your device and run the following command in the Terminal. Find your device in the output and find its serial number.
system_profiler SPUSBDataType
Put that serial number in the first line of this script...
set deviceSerialNumber to "CCCB1010221740331521362502"
try
set theResult to do shell script "system_profiler SPUSBDataType | grep " & deviceSerialNumber
set theStatus to "The device is available."
on error
set theStatus to "The device is not available."
end try
See if the script works by plugging and unplugging your device. If so then you have the basics of a solution. Now you just need a way to run this automatically. In applescript you can create a "stay-open" application and you can use that to run your script automatically every few seconds. You can google for how to create that.
NOTE: I do not think it is a good solution to have a script running every few seconds for this purpose. It's a waste of your computer's resources. However I can't think of another method to suggest. I really think your best solution is to just run your current script by hand.