AppleScript名:LAN上のファイルサーバー(smb)のホスト名を取得する |
— 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("_smb._tcp") of me –smb’s port:445 –> {"MBA13"} 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 17 times, 1 visits today)