Network Setup Scripting (was: Can't make data into expected type error)
Network Setup Scripting (was: Can't make data into expected type error)
- Subject: Network Setup Scripting (was: Can't make data into expected type error)
- From: email@hidden
- Date: Sun, 20 Oct 2002 12:58:56 EDT
Rob,
Late response, but I haven't seen anyone else chime in.
It appears "router address" is broken, plain and simple. Actually, it appears
to be unimplemented, despite suggestions to the contrary in its dictionary.
Try this sample code to understand more:
------------------------------------------------------------------------------
-----------
-- run this from Script Editor (I used AS 1.8.3 in MacOS 9.1 and 9.2.2, and
AS 1.3.7/MacOS 8.6)
-- keep the Event Log window open, with show events and event results both
checked
-- study the output
set x to my getRouterAddr()
log x
on getRouterAddr()
tell application "Network Setup Scripting"
try
open database
set tcpConfig to first TCPIP v4 configuration whose active is
true
set tcpProperties to properties of tcpConfig -- see all
properties
set IPaddr to IP address of tcpConfig -- joy!
set subnetMask to subnet mask of tcpConfig -- joy!
set connectingVia to connecting via of tcpConfig -- joy!
set routerAddress to router address of tcpConfig -- misery!
close database -- must close before you return
on error errmsg number errNum
close database -- safety first
set routerAddress to "error" -- otherwise the return statement
errs
log "Error: " & errmsg & " " & errNum -- read and cry
end try
end tell
return routerAddress -- return should be the last statement, outside any
blocks
end getRouterAddr
------------------------------------------------------------------------------
-----------
Learning pearls:
1) There can be only one config whose active is true. If you use "every
TCP/IP....." you get a list with one configuration. If you use "first
TCP/IP....." you get the configuration only. By using "first", you avoid the
need to extract item 1 from the list, as demonstrated (as wasteful technique)
below:
set tcpConfig to every TCPIP v4 configuration whose active is true
--> {TCPIP v4 configuration "LinkedResources Home LAN"}
set tcpConfig to (item 1 of tcpConfig)
--> TCPIP v4 configuration "LinkedResources Home LAN"
2) Apple has a brief tutorial about Network Setup Scripting at
http://docs.info.apple.com/article.html?artnum=30829&
SaveKCWindowURL=http://kbase.info.apple.com/cgi-bin/WebObjects/kba
se.woa/wa/SaveKCToHomePage&searchMode=Expert&kbhost=kbase.info.apple.com&
showButton=false&randomValue=100&showSurvey=false&
sessionID=anonymous|156068718
side note: the URL of that page used to be:
http://til.info.apple.com/techinfo.nsf/artnum/n30829
This helps us how?
3) Handler structure:
a) I believe return statements are really only for handlers. In your code,
I'm not sure where you would be returning to. Actually, I do know - you
return to Script Editor (if run as a compiled script), but that happens when
the script completes anyway, so it's unnecessary.
b) Once you return, code stops executing. In the sample code you posted, you
have this sequence:
>
return "router address = " & routerAddress
>
close database
>
quit
I don't believe the "close database" and "quit" lines would ever execute,
which would leave the database open, a Bad Thing(TM).
<style pref>
c) Handlers which get data/facts should return as limited a value as
necessary and leave any text formatting to other code.
</style pref>
4) NSS appears to have an odd bug under 9.2.2. Here is the event log under
9.2.2:
---------------- event log output --------- not a script --------------
tell application "Network Setup Scripting"
open database
open database
get TCPIP v4 configuration 1 whose active = true
--> TCPIP v4 configuration "Default"
get every property of TCPIP v4 configuration "Default"
--> {name:"Default", active:true, connecting via:"Ethernet",
configuration method:DHCP, IP address:"0.0.0.0", subnet mask:"0.0.0.0",
implicit search start:"", implicit search end:"", DHCP client ID:"", MacIP
server zone:"*", uses IEEE8023:false, protocol:TCPIP v4, user mode:basic}
get IP address of TCPIP v4 configuration "Default"
--> "216.203.195.144"
get subnet mask of TCPIP v4 configuration "Default"
--> "255.255.255.224"
get connecting via of TCPIP v4 configuration "Default"
--> "Ethernet"
get router address of TCPIP v4 configuration "Default"
close database
(*Error: Network Setup Scripting got an error: Can't make some data into
the expected type. -1700*)
(*error*)
end tell
-----------------------------------------------------------
Does anyone know what's with the "0.0.0.0"s in the properties? Obviously the
correct values are still accessible via AppleScript. This looks like another
bug to me.
HTH!
Jeff Baumann
jwbaumann(shift-2)aol(dot)com
www.linkedresources.com
In a message dated 10/16/02 12:14:57 AM, RGould8(shift-2)aol(dot)com writes:
>
Thanks to so many helpful folks on this listserve for aiding my efforts to
>
script the "Network Setup Scripting" panel. I've had 2 missions with
>
Applescript:
>
>
1) Set the user's network settings to DHCP (mission accomplished)
>
2) Retrieve the user's "router address" that comes back after DHCP is set.
>
(close, but no cigar)
>
>
My problem is this error message:
>
>
"Error: Network Setup Scripting got an error: Can't make some data into the
>
expected type. -1700"
>
>
when I run this script:
>
>
tell application "Network Setup Scripting"
>
try
>
with timeout of 30 seconds
>
open database
>
set tcpConfig to name of item 1 of every TCPIP v4 configuration
>
whose active is true
>
set routerAddress to router address of TCPIP v4 configuration
>
tcpConfig
>
return "router address = " & routerAddress
>
close database
>
quit
>
end timeout
>
>
on error errMsg number errNum
>
close database
>
beep
>
return "Error: " & errMsg & " " & errNum
>
end try
>
end tell
>
>
>
I did some tests by commenting out lines, and deduced that the problem is
>
with this line:
>
>
set routerAddress to router address of TCPIP v4 configuration tcpConfig
>
>
which is where I get the "Error: Network Setup Scripting got an error: Can't
>
make some data into the expected type. -1700" message.
>
>
What I'm having great difficulty figuring out is:
>
>
1) Is this a problem with one of my network settings that is incompatible
>
with the variable type that I'm trying to put it into?
>
2) Is this a problem with syntax?
>
>
>
Any help is greatly appreciated. Note that this script is designed to run
in
>
Mac OS 9.
>
>
- Rob
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.