Enter SIM card PIN via script for Huawei 3G USB modems
Tue, Apr 29 2008 at 7:30AM PDT • Contributed by: Mr. Bunbury
Tue, Apr 29 2008 at 7:30AM PDT • Contributed by: Mr. Bunbury
I always found it annoying that when I start Huawei's MobileConnect application, I must first enter the PIN for accessing the SIM card of my USB 3G modem before I can connect to the provider. Luckily, the program is rather verbose with debug output. So it was quite easy to retrieve the essential part for entering the PIN. It simply consists of some good old Hayes AT modem-communication commands.
I wrote a Perl script that fetches the PIN to your SIM card from a Keychain entry. In order to use this script, you have to create a Keychain entry under the account simpin. Here's how:
In my opinion, the easiest way to execute this perl script is by wrapping it in an Automator workflow:
After installing DSW, activate it and enter a new rule (with the modem disk already mounted). Mine is named web'n'walk, so I selected at 'When' web'n'walk Mounts and at 'What' Open YourAutomatorWorkflow/App, with 'After a Delay of' set to 0 seconds works fine for me. Don't forget to start Do Something When.
We can make the whole thing even a bit more convenient. As the mounted drive isn't actually needed, we could eject it:
I wrote a Perl script that fetches the PIN to your SIM card from a Keychain entry. In order to use this script, you have to create a Keychain entry under the account simpin. Here's how:
- Open Keychain Access (in Applications » Utilities)
- Menu: File » New Password Item
- Keychain Item Name: Enter something useful to you.
- Account Name: simpin
- Password: Enter the PIN to your SIM card (usually a number)
- Press Add
In my opinion, the easiest way to execute this perl script is by wrapping it in an Automator workflow:
- Open Automator
- Search for Run Shell Script
- Drag the Run Shell Script action to the large field at right.
- Select /usr/bin/perl for Shell, and set "Pass input" to 'to stdin'.
- Copy the perl script and paste it into the code field (delete example code first).
- Give it a test by pressing Run; just make sure you haven't entered the PIN already. If you have, disconnect the 3G modem briefly and wait a short while. Normally, you should be asked to allow access to the keychain entry.
After installing DSW, activate it and enter a new rule (with the modem disk already mounted). Mine is named web'n'walk, so I selected at 'When' web'n'walk Mounts and at 'What' Open YourAutomatorWorkflow/App, with 'After a Delay of' set to 0 seconds works fine for me. Don't forget to start Do Something When.
We can make the whole thing even a bit more convenient. As the mounted drive isn't actually needed, we could eject it:
- Go back to the Automator workflow.
- Search for Run AppleScript
- Add the Run AppleScript action above the Run Shell Script action in the work area.
- Paste the following into the code field:
Change web'n'walk' to the drive name of your 3Gmodem.on run {input, parameters} tell application "Finder" activate eject disk "web'n'walk" end tell return input end run - Save the workflow again and make sure it is selected correctly in the Do Something When System Preferences panel.
•
[10,208 views]
