Re: machine IP address
Re: machine IP address
- Subject: Re: machine IP address
- From: Stan Cleveland <email@hidden>
- Date: Tue, 25 Jul 2006 14:52:33 -0700
- Thread-topic: machine IP address
Title: Re: machine IP address
On 7/25/06 2:17 PM, John C. Welch wrote:
<snip>
this script:
property theServiceInfo : "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -getinfo "
set theServiceList to do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -listallnetworkservices"
set theServiceList to every paragraph of theServiceList
set theServiceList to the rest of theServiceList --the first item is the explanatory text about the asterisk, and we don't need it
set theEnabledServices to {}
set theIPAddressList to {}
repeat with x in theServiceList --get a list of enabled services
if the first character of x is not "*" then
set the end of theEnabledServices to contents of x
end if
end repeat
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
try
repeat with x in theEnabledServices
set theIPAddress to do shell script theServiceInfo & (quoted form of the contents of x) & "|/usr/bin/grep \"IP address\""
set theIPAddress to every text item of theIPAddress
set the end of theIPAddressList to (contents of x) & ": " & (last text item of theIPAddress)
end repeat
end try
set AppleScript's text item delimiters to oldDelims
should get you most of the way there.
Very nice! However, in the last group of lines of code, it looks like the “try” block should be inside the “repeat” loop, rather than the other way around. Like this:
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
repeat with x in theEnabledServices
try
set theIPAddress to do shell script theServiceInfo & (quoted form of the contents of x) & "|/usr/bin/grep \"IP address\""
set theIPAddress to every text item of theIPAddress
set the end of theIPAddressList to (contents of x) & ": " & (last text item of theIPAddress)
end try
end repeat
set AppleScript's text item delimiters to oldDelims
With this change, if any IP address is not found, the script will continue to check the remaining services rather than aborting.
Stan Cleveland
Color Technology Inc.
Portland, Oregon
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden