AppleScript名:郵便専門ネットでXML-RPC経由で引数に都道府県のJISコード(JISコードの先頭2文字)を渡すと、その都道府県に属しているJISコードを取得 |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.jiscodeFromPrefcode", parameters:{"13"}} end tell –> {"13101", "13102", "13103", "13104", "13105", "13106", "13107", "13108", "13109", "13110", "13111", "13112", "13113", "13114", "13115", "13116", "13117", "13118", "13119", "13120", "13121", "13122", "13123", "13201", "13202", "13203", "13204", "13205", "13206", "13207", "13208", "13209", "13210", "13211", "13212", "13213", "13214", "13215", "13218", "13219", "13220", "13221", "13222", "13223", "13224", "13225", "13227", "13228", "13229", "13303", "13305", "13307", "13308", "13361", "13362", "13363", "13364", "13381", "13382", "13401", "13402", "13421"} |
タグ: 10.13savvy
郵便専門ネットで一度に取得できるデータ件数を返す
AppleScript名:郵便専門ネットで一度に取得できるデータ件数を返す |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.getMaxFetchCount", parameters:{}} end tell –> 100 |
郵便専門ネットで郵便番号を5桁の全国地方公共団体コード/JISコード/市町村コードに変換
AppleScript名:郵便専門ネットで郵便番号を5桁の全国地方公共団体コード/JISコード/市町村コードに変換 |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.postcodeExists", parameters:{"1760024"}} end tell –> true |
郵便専門ネットで郵便番号の存在チェック
AppleScript名:郵便専門ネットで郵便番号の存在チェック |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.postcodeExists", parameters:{"1760024"}} end tell –> true |
郵便専門ネットで道府県のコード(地方公共団体コードの先頭2文字)から都道府県名を返す
AppleScript名:郵便専門ネットで道府県のコード(地方公共団体コードの先頭2文字)から都道府県名を返す |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.getPrefName", parameters:{"13"}} end tell –> "東京都" |
郵便専門ネットで引数に指定した郵便番号で何件ヒットするのかをint型で返す
AppleScript名:郵便専門ネットで引数に指定した郵便番号で何件ヒットするのかをint型で返す |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.getFetchCountByPostcode", parameters:{"1980036"}} end tell –> 1 |
郵便専門ネットでXML-RPC経由で郵便番号から住所を返す
AppleScript名:郵便専門ネットでXML-RPC経由で郵便番号から住所を返す |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.fetchAddressByPostcode", parameters:{"1760022"}} end tell –> {{other:application "http://yubin.senmon.net/service/xmlrpc/", addr_name:application "http://yubin.senmon.net/service/xmlrpc/", yid:176002201, postcode:"1760022", data_type:"p", addr_name_kana:application "http://yubin.senmon.net/service/xmlrpc/", city_kana:"ねりまく", jiscode:"13120", town:"向山", town_kana:"こうやま", city:"練馬区", pref:"東京都", pref_kana:"とうきょうと"}} |
郵便専門ネットでXML-RPC経由で郵便番号に対応する世界測地系(WGS84)の緯度経度コード(Geocode)を返す
AppleScript名:郵便専門ネットでXML-RPC経由で郵便番号に対応する世界測地系(WGS84)の緯度経度コード(Geocode)を返す |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.postcodeToGeocode", parameters:{"1760024"}} end tell –> {35.0345563, 135.7476776} |
郵便専門ネットでXML-RPC経由でJISコード(5桁、6桁どちらでも)から、その市区町村に属している郵便番号のリストを取得
AppleScript名:郵便専門ネットでXML-RPC経由でJISコード(5桁、6桁どちらでも)から、その市区町村に属している郵便番号のリストを取得 |
tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.postcodeFromJiscode", parameters:{"011037"}} end tell –> {"0070001", "0070002", "0070003", "0070004", "0070005", "0070006", "0070011", "0070030", "0070031", "0070032", "0070033", "0070034", "0070801", "0070802", "0070803", "0070804", "0070805", "0070806", "0070807", "0070808", "0070809", "0070810", "0070811", "0070812", "0070813", "0070814", "0070815", "0070819", "0070820", "0070821", "0070822", "0070823", "0070824", "0070825", "0070826", "0070827", "0070828", "0070829", "0070834", "0070835", "0070836", "0070837", "0070838", "0070839", "0070840", "0070841", "0070842", "0070843", "0070844", "0070845", "0070846", "0070847", "0070848", "0070849", "0070850", "0070851", "0070852", "0070861", "0070862", "0070863", "0070864", "0070865", "0070866", "0070867", "0070868", "0070869", "0070870", "0070871", "0070872", "0070873", "0070874", "0070880", "0070881", "0070882", "0070883", "0070884", "0070885", "0070886", "0070890", "0070891", "0070892", "0070893", "0070894", "0070895", "0078501", "0078503", "0078505", "0078507", "0078508", "0078553", "0078585", "0078632", "0600905", "0600906", "0600907", "0600908", "0600909", "0608569", "0608576", "0608582", "0650000", "0650004", "0650005", "0650006", "0650007", "0650008", "0650009", "0650010", "0650011", "0650012", "0650013", "0650014", "0650015", "0650016", "0650017", "0650018", "0650019", "0650020", "0650021", "0650022", "0650023", "0650024", "0650025", "0650026", "0650027", "0650028", "0650030", "0650031", "0650032", "0650033", "0650041", "0650042", "0650043", "0658501", "0658508", "0658510", "0658511", "0658518", "0658522", "0658533", "0658543", "0658550", "0658555", "0658558", "0658567", "0658578", "0658601", "0658609", "0658610", "0658611", "0658612", "0658633", "0658639"} |
郵便専門ネットでバージョン番号を取得
AppleScript名:郵便専門ネットでバージョン番号を取得 |
–http://yubin.senmon.net/service/xmlrpc/ tell application "http://yubin.senmon.net/service/xmlrpc/" call xmlrpc {method name:"yubin.getVersion", parameters:{}} end tell –>"18.01a" |
ドメイン名からIPアドレスを取得
AppleScript名:ドメイン名からIPアドレスを取得 |
— Created 2016-04-03 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set anIP to ((current application’s NSHost’s hostWithName:"www.google.com")’s address()) as string –> "216.58.200.196" |
インターネット接続確認
AppleScript名:インターネット接続確認 |
— Created 2015-12-16 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRes to hasInternetConnection() of me –> true on hasInternetConnection() set aURL to current application’s |NSURL|’s alloc()’s initWithString:"http://www.google.com" set aReq to current application’s NSURLRequest’s alloc()’s initWithURL:aURL cachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:5.0 set urlRes to (current application’s NSURLConnection’s sendSynchronousRequest:aReq returningResponse:(missing value) |error|:(missing value)) if urlRes = missing value then return false else return true end if end hasInternetConnection |
Twitter投稿
macOS 10.13まではTwitter投稿やFacebook連携などもOSに組み込まれていたので、手軽にこうした機能を利用でき、macOS 10.13までの環境ではこのように呼び出せるようになっていました。
macOS 10.14から方針が変わり、これらの機能はOSに組み込まれなくなりました。いまだと、REST API経由で投稿を行うことになるでしょうか。
AppleScript名:Twitter投稿 |
— Created 2015-01-24 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aString to "ぴよ〜" set twService to current application’s NSSharingService’s sharingServiceNamed:(current application’s NSSharingServiceNamePostOnTwitter) set twService’s delegate to me set shareItems to current application’s NSMutableArray’s alloc()’s initWithObjects:aString tell twService to performWithItems:shareItems |
AirDropでファイルを送信する
Sharing Utilitiesを用いてAirDrop経由のファイル送信を行うAppleScriptです。
さすがに、Sharing Utilitiesは仕様も古いので、最新の環境に合わせて書き換えた「AirSharingLib Script Library」を配布、そちらを用いて同様の機能を実現するAppleScriptも掲載しています。
AppleScript名:AirDropでファイルを送信する |
use AppleScript version "2.4" use scripting additions use framework "Foundation" use shareLib : script "Sharing Utilities" –https://macosxautomation.com/mavericks/libraries/examples.html set anItem to choose file with prompt "Select File to send via AirDrop" set aaList to {anItem} begin AirDrop with aaList |
LAN上のHDDをマウントする v2
AppleScript名:LAN上のHDDをマウントする v2 |
–SMB経由でマウント set userAccount to "maro" –ユーザー名(環境に応じて書き換え) set userPass to "xxxxxx" –パスワード(環境に応じて書き換え) set aMachine to "smb://MBA11._smb._tcp.local/Macintosh HD" –11インチMacBook Air (10.9.2)でSMBのみ有効にしてテスト mountVolume(aMachine, userAccount, userPass) of me –通常実行 –AFP経由でマウント set userAccount to "maro" –ユーザー名(環境に応じて書き換え) set userPass to "xxxxxx" –パスワード(環境に応じて書き換え) set aMachine to "afp://MBA13._afpovertcp._tcp.local/Macintosh SSD" –13インチMacBook Air (10.7.5)でAFPとSMBの両方を有効にしてテスト mountVolumeAsync(aMachine, userAccount, userPass) of me –非同期実行 –指定のネットワーク上のディスクをマウントする on mountVolume(aMachine, userAccount, userPass) try with timeout of 100 seconds mount volume aMachine as user name userAccount with password userPass end timeout on error return false end try return true end mountVolume –指定のネットワーク上のディスクをマウントする(非同期実行) on mountVolumeAsync(aMachine, userAccount, userPass) try ignoring application responses mount volume aMachine as user name userAccount with password userPass end ignoring on error — end try end mountVolumeAsync |
無線LANデバイスのMACアドレスを取得する
AppleScript名:無線LANデバイスのMACアドレスを取得する |
— Created 2015-08-18 by Takaaki Naganoya — Created 2015-08-18 by Shane Stanley — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "CoreWLAN" set aRes to retWiFiMACaddress() –> "XX:XX:XX:XX:XX:XX" –WiFi DeviceのMAC ADDRESSを返す on retWiFiMACaddress() –Get WLAN Device Name set allNames to current application’s CWInterface’s interfaceNames()’s allObjects() –> (NSArray) {"en0"} –@MacBook Pro Retina 2012 set hitF to false repeat with i from 1 to allNames’s |count|() set aInterface to (current application’s CWInterface’s interfaceWithName:(allNames’s objectAtIndex:(i – 1))) if aInterface’s serviceActive() as boolean then set hitF to true exit repeat end if end repeat if hitF = false then return false –There is No WiFi Device (Broken or illigal configuration or Hackintosh) set aHWAddress to aInterface’s hardwareAddress() as text –> "b8:xx:xx:xx:xx:xx"–MAC Address return aHWAddress end retWiFiMACaddress |
無線LANの各種情報を取得する v2.2
AppleScript名:無線LANの各種情報を取得する v2.2 |
— Created 2015-08-18 by Shane Stanley — Modified 2015-08-18 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "CoreWLAN" –Get WLAN Device Name set allNames to current application’s CWInterface’s interfaceNames()’s allObjects() log allNames as list of string or string –> (NSArray) {"en0"} –@MacBook Pro Retina 2012 set hitF to false repeat with i from 1 to allNames’s |count|() set aInterface to (current application’s CWInterface’s interfaceWithName:(allNames’s objectAtIndex:(i – 1))) if aInterface’s serviceActive() as boolean then set hitF to true exit repeat end if end repeat if hitF = false then return false –There is No WiFi Device –WiFi device is Power On ? repeat 10 times set aPower to (aInterface’s powerOn()) as boolean if aPower = false then –ActiveなWLANがない場合(WiFiをオフにしている)にはWiFiパワーオン set wRes to aInterface’s setPower:true |error|:(missing value) delay 1 else exit repeat end if end repeat if aPower = false then return false –I could not power on WiFi deveice set aChan to aInterface’s wlanChannel() –> (CWChannel) <CWChannel: 0x60000040cdd0> [channelNumber=1(2GHz), channelWidth={20MHz}] set chanNumber to aChan’s channelNumber() log chanNumber –> 52 set chanBand to aChan’s channelBand() — 0 = unknown, 1 = 2GHz, 2 = 5GHz log chanBand –> 2 set chanWidth to aChan’s channelWidth() — 0 = unknown, 1 = 20MHz, 2 = 40MHz log chanWidth –> 2 set aTransRate to aInterface’s transmitRate() log aTransRate –> 162.0 set aChannnels to aInterface’s supportedWLANChannels() –> (NSSet) {(CWChannel) <CWChannel: 0x60800020fad0> [channelNumber=1(2GHz), channelWidth={20MHz}, active], (CWChannel) <CWChannel: 0x60800020fb90> [channelNumber=2(2GHz), channelWidth={20MHz}, active], ……………(CWChannel) <CWChannel: 0x608000208410> [channelNumber=64(5GHz), channelWidth={20MHz}, DFS], (CWChannel) <CWChannel: 0x60800020f9e0> [channelNumber=136(5GHz), channelWidth={20MHz}, DFS]} set aSSIDdata to aInterface’s ssidData() –> (NSData) <45787472 xxxxxxxx xxxxxxxx xxxx> set aSSID to aInterface’s ssid() as text –> "Extreme net_5G" set aActive to aInterface’s serviceActive() –> true set aSecurity to aInterface’s security() –> 4 set aRSSIval to aInterface’s rssiValue() –> -72 set aPower to aInterface’s powerOn() –> true set aNoise to aInterface’s noiseMeasurement() –> -91 set aIFname to aInterface’s interfaceName() as text –> "en0" set aMode to aInterface’s interfaceMode() –> 1 set aHWAddress to aInterface’s hardwareAddress() as text –> "b8:xx:xx:xx:xx:xx"–MAC Address set aCountry to aInterface’s countryCode() as text –> "JP" set aConfig to aInterface’s configuration() –> (CWConfiguration) <CWConfiguration: 0x6100002348e0> set aCacheRes to aInterface’s cachedScanResults() –> (NSSet) {(CWNetwork) <CWNetwork: 0x618000402740> ……………… [channelNumber=11(2GHz), channelWidth={20MHz}], ibss=0]} set aBSSID to aInterface’s bssid() as text –> "10:XX:XX:XX:XX:XX" set aPhyMode to aInterface’s activePHYMode() –> 4 |
WiFiデバイスのパワーをオンに
AppleScript名:WiFiデバイスのパワーをオンに |
— Created 2015-08-18 by Shane Stanley — Modified 2015-08-18 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "CoreWLAN" set wRes to powerOnEveryWiFiDevices() of me on powerOnEveryWiFiDevices() set allNames to current application’s CWInterface’s interfaceNames()’s allObjects() as list if allNames = {} then return false set powerList to {} repeat with i in allNames set j to contents of i set aInterface to (current application’s CWInterface’s interfaceWithName:j) set wRes to (aInterface’s setPower:true |error|:(missing value)) set aPower to (aInterface’s powerOn()) as boolean if aPower = false then display notification "Error occured in enabling an Wifi deviece ( " & j & " )…." end if set the end of powerList to aPower end repeat return ({true} is in powerList) –return whether some WiFi interface is on end powerOnEveryWiFiDevices |
LAN上のファイルサーバー(smb)のホスト名を取得する
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: |
LAN上のファイルサーバー(afp)のホスト名を取得する
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: |