First off, I haven’t owned a mac for very long, and I’ve had very little exposure to Applescript. I’m working on a project for work in which I can automatically map a network drive based on the SSID or BSSID of the wireless network I connect to(if I connect to my home network, I map my home drive, if at work, I map our file server). Here’s what I’ve got so far:
tell application "Internet Connect"
if network name = "test" then
display dialog "You're on your home network!"
else
display dialog "What?"
end if
end tell
All I’m trying to get it to do there is get it to register that I’m connecting to a specific network with the SSID “test”. It compiles fine, but I get the error “Internet Connect got an error: Can’t make network name into type reference.” I’m assuming this has something to do with the type of object that “network name” is. The Internet Connect Applescript dictionary says it’s Unicode text, so I’m a little confused why this doesn’t work (it’s probably something really obvious that I just haven’t seen yet. If somebody could point me in the right direction and maybe explain how data types on each side of the qualifiers work, I’d really appreciate it.
i’m completely new to this. the most extensive applescript i’ve written was a samba script to mount some network drives. but, reading what you’ve got there…couldn’t you use the mac address instead of the SSID? maybe that’s what the error is implying? don’t know. but i’d give that a shot first.
I tried using the BSSID, but it appears I can’t get anything from that Internet Connect stuff to fit into a variable. Like I said, I’m sure it’s something simple.
I don’t have a wireless network to check this on, but this should tell you what wireless connection you are currently using (or returns “wireless network not available” if none present):
set NetName to do shell script ("system_profiler SPAirPortDataType |grep -e " & quoted form of "Current Wireless Network:" & " |awk '{print $4,$5,$6,$7}'")
I’m just beginning to get to grips with shell scripting myself, and so what I achieve is as much by trial and error and experimentation with other postings as anything else, but - the little I understand goes something like this:
do shell script = using applescript to execute terminal-style commands
system_profiler SPAirPortDataType= queries system configuration, in the same way that “Apple Menu → About this Mac → More info does”
See http://www.hmug.org/man/8/system_profiler.php for details.
grep -e = a text search
See http://www.mkssoftware.com/docs/man1/grep.1.asp
quoted form of = allows a string to be read as literal, including spaces, etc. within a shell script command
awk = another search tool, but with flexibility on what elements of the found text are displayed
See http://www.vectorsite.net/tsawk1.html#m1
print $4,$5… etc was just my way of ensuring that the first 3 words of the found text were not displayed
That pretty much exhausts my current knowledge of shell scripting. It’s a pretty long learning curve, but rumour has it that it’s worth it!
Have fun,
PJ.