is there any way to get a list of any networked machines, and their locations like “Bobs-Computer.local”
Hi,
I use this to determine the servers a their IP addresses
tell application "System Events" to set servers to name of disk items of disk "Network" whose its file type is "slua"
set serverIPs to {}
repeat with i in servers
set theIP to do shell script "arp -n " & i & ".local | cut -f 2 -d '(' | cut -f 1 -d ')'"
if theIP is "" then
set end of serverIPs to "not available"
else
set end of serverIPs to {contents of i, theIP}
end if
end repeat
it returns not available, but i see a networked computer in my network folder
EDIT: i think its because the natworked computers names have spaces in them, when the path to them is dashes like… Bobs-Computer.local and the name would be Bob’s Computer
Ok, then you have to “escape” the characters
tell application "System Events" to set servers to name of disk items of disk "Network" whose its file type is "slua"
set serverIPs to {}
repeat with i in servers
set theIP to do shell script "arp -n " & escape_chrs(i) & ".local | cut -f 2 -d '(' | cut -f 1 -d ')'"
if theIP is "" then
set end of serverIPs to "not available"
else
set end of serverIPs to {contents of i, theIP}
end if
end repeat
on escape_chrs(t)
set {TID, text item delimiters} to {text item delimiters, " "}
set t to text items of t
set text item delimiters to "-"
set t to t as Unicode text
set text item delimiters to "'"
set t to text items of t
set text item delimiters to TID
set t to t as Unicode text
return t
end escape_chrs
it doesnt work, whenever i type it into script editor or an applescript studio app it doesnt do anything. it worked the first few times but now it doesnt.
I’m sorry, I’ve tested it on two machines (PPC 10.4.10) and it works solidly
thats weird
its this part of the code
tell application "System Events" to set servers to name of disk items of disk "Network" whose its file type is "slua"
is there any alternative way of doing that, thats the only part i need for my app i dont need the ip part or anything.
EDIT: i fixed it. the problem was that i have a networked pc in my network folder, so it puts all the mac networked computers in a folder called “My Network” without the quotes, so doing this simply fixed my problem:
tell application "System Events" to set servers to name of disk items of folder "My Network" of disk "Network" whose its file type is "slua"
is there a way to use escapt characters to get rid of everything except for letters and numbers so if there are any weird characters in the computer name it will always end up like “blah-blahs-computer.local”
:lol:, I knew, there must be a special reason
You can use the escape_chrs() routine above, it omits single quotes and changes spaces to hyphens.
If you want to extend the routine you should do it according to Apple to specify the name for the network
ok i didnt notice that it also took out sigle quotes. thanks it works.
ok i take that back, it doesnt seem to eliminate single quotes. heres what i have:
tell application "Finder"
if exists folder "My Network" of disk "Network" then
tell application "System Events" to set servers to name of disk items of folder "My Network" of disk "Network" whose its file type is "slua"
else
tell application "System Events" to set servers to name of disk items of disk "Network" whose its file type is "slua"
end if
end tell
set comps to {}
repeat with i in servers
set theComp to escape_chrs(i) & ".local"
set end of comps to contents of theComp
end repeat
return comps
on escape_chrs(t)
set {TID, text item delimiters} to {text item delimiters, " "}
set t to text items of t
set text item delimiters to "-"
set t to t as Unicode text
set text item delimiters to "'"
set t to text items of t
set text item delimiters to TID
set t to t as Unicode text
end escape_chrs
it could be, that your text item delimiters are corrupted,
so the final set to TID fails, or the single quote is not really a single quote
or the text encoding causes a problem.
Try this robust version
on escape_chrs(t)
set {TID, text item delimiters} to {text item delimiters, " "}
set t to text items of (t as string)
set text item delimiters to "-"
set t to t as string
set text item delimiters to (ASCII character 39)
set t to text items of t
set text item delimiters to ""
set t to t as string
set text item delimiters to TID
return t as Unicode text
end escape_chrs
nope still didnt work.
I don’t understand this at all
on my machine
escape_chrs("abc'def hi' k.local" as Unicode text)
results
"abcdef-hi--k.local"
yeah i just tried that on mine and it returned the same result
And what doesn’t work?
what wrong results do you get?
ok lets say this is the name of the computer:
“Bob Smith’s Computer”
i am getting this:
“Bob-Smith’s-Computer.local”
all is good except for the quote.
Then I guess, that Apple uses a different character as ASCII 39.
I’ve named all my computers, so I can not check the default setting
you can check the ASCII number with this routine (replace temporarily the original escape_chrs)
on escape_chrs(t)
repeat with i in (characters of (t as string))
display dialog ((ASCII number i) as string) & " - " & i
end repeat
return t
end escape_chrs
i figured it out, its not a real quote i copied and pasted it from the computer name. so now its working. thanks for all your help.