LAN上のdaap(Music/iTunesライブラリ共有)サービス名を検出するAppleScriptです。
LAN上の他のマシンで動作中のサービス名を収集します。AppleScriptを実行している自機のサービスは除外しています。
他のフォーラムへの無断転載、および転載時にもヘッダー部分を削除することを厳禁します。
AppleScript名:LAN上のdaapクライアントの共有名をリストアップ v2.scptd |
— – Created by: Takaaki Naganoya – Created on: 2021/05/11 — – Copyright © 2021 Piyomaru Software, All Rights Reserved — http://piyocast.com/as/ — – ** You are allowed to use this AppleScript with holding this header comment ** – ** Don’t re-post this script to other forums without this header comment ** – ** I’m very angry with removing header comment ** use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property foundList : {} property myHostNames : {} property services : {} property comingF : false property resolveF : false set mList to findHostsViaBonjour("_daap._tcp", "") of me –> {"Takaaki Naganoya のライブラリ", "ぴよぴよ ライブラリ"} on findHostsViaBonjour(aType as string, aDomain as string) set my foundList to {} set my comingF to true set my resolveF to false set my myHostNames to (current application’s NSHost’s currentHost()’s names()) as list –> {"MacMini2014.local", "macmini2014.local", "localhost"} set aBrowser to current application’s NSNetServiceBrowser’s alloc()’s init() aBrowser’s setDelegate:me aBrowser’s searchForServicesOfType:aType inDomain:aDomain repeat 100 times if my comingF = false then if my foundList is not equal to {} then exit repeat end if delay 0.01 end repeat repeat 100 times if my resolveF = false then if my foundList is not equal to {} then exit repeat end if delay 0.01 end repeat aBrowser’s setDelegate:(missing value) return (my foundList) end findHostsViaBonjour –searchForServicesOfTypeのdelegate on netServiceBrowser:aNetServiceBrowser didFindService:aNetService moreComing:aMoreComing copy (aMoreComing as boolean) to my comingF set my resolveF to true aNetService’s setDelegate:me set cInfo to aNetService’s resolveWithTimeout:3 end netServiceBrowser:didFindService:moreComing: –NetService’s resolveWithTimeoutのdelegate on netServiceDidResolveAddress:aSender set cDesc to (aSender’s |name|()) as string set dDesc to (aSender’s |hostName|()) as string aSender’s |stop|() –すげー大事 set dDesc to repChar(dDesc, ".local.", ".local") of me if dDesc is not in (my myHostNames) then set the end of (my foundList) to cDesc end if end netServiceDidResolveAddress: –文字置換 on repChar(origText as string, targChar as string, repChar as string) set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to targChar set tmpList to text items of origText set AppleScript’s text item delimiters to repChar set retText to tmpList as string set AppleScript’s text item delimiters to curDelim return retText end repChar |