Get list of machines on Local Network?

Looking for a way to generate a list of all machines on local network, essentially all the machines listed in the “Network” location you can see in Finder. Anyone know if this is possible using AppleScript or a shell command?

For example:
{“machine1.local”, “machine2.local”, etc.}

Hi,

is this sufficient?


choose URL showing File servers

You sir, are amazing. The only other thing I am really after is getting them in list form, and maybe a way to only show AFP file servers. I would like them in list form so I can allow multiple selections.

Thanks again, you always come through.

Unfortunately AppleScript cannot list the AFP-servers.
Apple has broken this functionality since Leopard.

For this purpose I wrote a little Foundation tool CLI, you can download it here:
AFPHosts

Save it somewhere and call it with do shell script

That’s too bad, need to find a contact at Apple who can pull some strings and get that fixed.

Is it possible to use delimiters to get the result of AFPHosts in list form rather than line for line?

paragraphs of (do shell script . )

Amazing, thanks. You have helped me out so many times can’t thank you enough sir.

Ignore last request

Great, got it all up and running I am just running into the problem of properly storing that in a .plist using defaults. I can’t seem to find a way to keep my list comma separated when it is stored away in the .plist. I have tried storing as an array but it seems more difficult to read those values back later as it doesn’t read back in a list format at all.

Basically, I am getting this “machine1.localmachine2.local” instead of “machine1.local, machine2.local, etc” I ran into this before and never found a good solution.


set serverList to paragraphs of (do shell script "/path/to/AFPHosts")
set {TID, text item delimiters} to {text item delimiters, ", "}
set serverList to serverList as text
set text item delimiters to TID
serverList

PERFECT! This will benefit many of my other scripts as well. Cheers to you!

I think the last thing on my agenda is to read those back into my script so the user can choose them from a list.

Here is a snippet with what I need to accomplish:



--SET REMOTE MACHINE PREFERENCES
set remoteMachineList to paragraphs of (do shell script "/Users/andoru/Downloads/AFPHosts")
set remoteMachines to (choose from list remoteMachineList with prompt "Choose additional machines on your network to use for rendering:" with title "RenderQ" OK button name "Select" cancel button name "Local Render Only" with multiple selections allowed)

if remoteMachines = false then
	do shell script "defaults write com.andorulabs.renderq remoteMachines Local"
else
	set {TID, text item delimiters} to {text item delimiters, ", "}
	set remoteMachines to remoteMachines as text
	set text item delimiters to TID
	do shell script "defaults write com.andorulabs.renderq remoteMachines '" & remoteMachines & "'"
end if


--READ PREFS AND ASK TO CHOOSE FROM LIST
set theList to (do shell script "defaults read com.andorulabs.renderq remoteMachines")
set choice to choose from list theList with multiple selections allowed


But I am only getting a one item list to choose from, “machine1.local, machine2.local, machine3.local”

There must be a way to read in the ", " separated values as a proper list correct?

Resolved the problem with this:



set readList to (do shell script "defaults read com.andorulabs.renderq remoteMachines")
set text item delimiters to ", "
set machineList to text items of readList
set text item delimiters to {""}