AppleScript名:LAN上のファイルサーバー(afp)のホスト名を取得する |
— Created 2015-12-24 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" property foundHosts : {} property myHostName : "" findHostsViaBonjour("_afpovertcp._tcp") of me –AFP’s port:548 –> {"MBA13", "Mini_2", "MBA11"} on findHostsViaBonjour(aType) set foundHosts to {} set myHostName to (current application’s NSHost’s currentHost()’s localizedName()) as string set aBrowser to current application’s NSNetServiceBrowser’s alloc()’s init() aBrowser’s setDelegate:me aBrowser’s searchForServicesOfType:aType inDomain:"" repeat 1000 times if foundHosts is not equal to {} then exit repeat delay 0.01 end repeat aBrowser’s setDelegate:(missing value) return foundHosts end findHostsViaBonjour on netServiceBrowser:aNetServiceBrowser didFindService:aNetService moreComing:aMoreComing set aDesc to aNetServiceBrowser’s |description|() set bDesc to aNetService’s |description|() set cDesc to (aNetService’s |name|()) as text if cDesc is not in foundHosts and cDesc is not equal to myHostName then set the end of foundHosts to cDesc end if end netServiceBrowser:didFindService:moreComing: |
More from my site
(Visited 35 times, 1 visits today)