Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

カテゴリー: Network

郵便専門ネットで一度に取得できるデータ件数を返す

Posted on 2月 11, 2018 by Takaaki Naganoya
AppleScript名:郵便専門ネットで一度に取得できるデータ件数を返す
tell application "http://yubin.senmon.net/service/xmlrpc/"
  call xmlrpc {method name:"yubin.getMaxFetchCount", parameters:{}}
end tell
–> 100

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

郵便専門ネットで郵便番号を5桁の全国地方公共団体コード/JISコード/市町村コードに変換

Posted on 2月 11, 2018 by Takaaki Naganoya
AppleScript名:郵便専門ネットで郵便番号を5桁の全国地方公共団体コード/JISコード/市町村コードに変換
tell application "http://yubin.senmon.net/service/xmlrpc/"
  call xmlrpc {method name:"yubin.postcodeExists", parameters:{"1760024"}}
end tell
–> true

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

郵便専門ネットで郵便番号の存在チェック

Posted on 2月 11, 2018 by Takaaki Naganoya
AppleScript名:郵便専門ネットで郵便番号の存在チェック
tell application "http://yubin.senmon.net/service/xmlrpc/"
  call xmlrpc {method name:"yubin.postcodeExists", parameters:{"1760024"}}
end tell
–> true

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

郵便専門ネットで道府県のコード(地方公共団体コードの先頭2文字)から都道府県名を返す

Posted on 2月 11, 2018 by Takaaki Naganoya
AppleScript名:郵便専門ネットで道府県のコード(地方公共団体コードの先頭2文字)から都道府県名を返す
tell application "http://yubin.senmon.net/service/xmlrpc/"
  call xmlrpc {method name:"yubin.getPrefName", parameters:{"13"}}
end tell
–> "東京都"

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

郵便専門ネットで引数に指定した郵便番号で何件ヒットするのかをint型で返す

Posted on 2月 11, 2018 by Takaaki Naganoya
AppleScript名:郵便専門ネットで引数に指定した郵便番号で何件ヒットするのかをint型で返す
tell application "http://yubin.senmon.net/service/xmlrpc/"
  call xmlrpc {method name:"yubin.getFetchCountByPostcode", parameters:{"1980036"}}
end tell
–> 1

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

郵便専門ネットでXML-RPC経由で郵便番号から住所を返す

Posted on 2月 11, 2018 by Takaaki Naganoya
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:"とうきょうと"}}

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

郵便専門ネットでXML-RPC経由で郵便番号に対応する世界測地系(WGS84)の緯度経度コード(Geocode)を返す

Posted on 2月 11, 2018 by Takaaki Naganoya
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}

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

郵便専門ネットでXML-RPC経由でJISコード(5桁、6桁どちらでも)から、その市区町村に属している郵便番号のリストを取得

Posted on 2月 11, 2018 by Takaaki Naganoya
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"}

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

郵便専門ネットでバージョン番号を取得

Posted on 2月 11, 2018 by Takaaki Naganoya
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"

★Click Here to Open This Script 

Posted in Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

ドメイン名からIPアドレスを取得

Posted on 2月 11, 2018 by Takaaki Naganoya
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"

★Click Here to Open This Script 

Posted in Network System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

インターネット接続確認

Posted on 2月 11, 2018 by Takaaki Naganoya
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

★Click Here to Open This Script 

Posted in Network System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Twitter投稿

Posted on 2月 11, 2018 by Takaaki Naganoya

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

★Click Here to Open This Script 

Posted in Network System | Tagged 10.11savvy 10.12savvy 10.13savvy Twitter

AirDropでファイルを送信する

Posted on 2月 11, 2018 by Takaaki Naganoya

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

★Click Here to Open This Script 

Posted in AirDrop Network System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

LAN上のHDDをマウントする v2

Posted on 2月 11, 2018 by Takaaki Naganoya
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

★Click Here to Open This Script 

Posted in Network System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

無線LANデバイスのMACアドレスを取得する

Posted on 2月 11, 2018 by Takaaki Naganoya
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

★Click Here to Open This Script 

Posted in Network System WiFi | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

無線LANの各種情報を取得する v2.2

Posted on 2月 11, 2018 by Takaaki Naganoya
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

★Click Here to Open This Script 

Posted in Network System WiFi | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

WiFiデバイスのパワーをオンに

Posted on 2月 11, 2018 by Takaaki Naganoya
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

★Click Here to Open This Script 

Posted in Network System WiFi | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

LAN上のファイルサーバー(smb)のホスト名を取得する

Posted on 2月 11, 2018 by Takaaki Naganoya
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:

★Click Here to Open This Script 

Posted in Network System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

LAN上のファイルサーバー(afp)のホスト名を取得する

Posted on 2月 11, 2018 by Takaaki Naganoya
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:

★Click Here to Open This Script 

Posted in Network System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

WordPress XML-RPC Frameworkのじっけん

Posted on 2月 8, 2018 by Takaaki Naganoya

WordPress XML-RPC Frameworkを呼び出して、指定のWordPressとXML-RPCによる通信を行うテスト用のAppleScriptです。

# 本BlogではAppleScriptからの自動更新時以外はWordPressのXML-RPC通信機能をプラグイン「Disable XML-RPC」によって止めているので、本Scriptを実行してもエラーになる可能性があります。他のWordPressのサイトでお試しください

本Blogがホスティング業者との行き違いでデータベースをシャットダウンされて、やむなく再構築を行おうと決意してから迅速に再構築を進めて来られたのは、手元にAppleScriptの元コードがすべて無傷で残っていたことと、これまで半自動だった記事の投稿をすべてAppleScriptから自動化できる目処が立っていたためでした。

・指定のAppleScriptをHTML化(URLリンク付き)するAppleScriptライブラリ
・指定内容のHTMLをWordPressにXML-RPC経由で投稿するAppleScript

といった「飛び道具」を整備することで、指定のAppleScript書類をWordPressに投稿できるようになりました。

とくに、XML-RPCについてはAppleScriptの標準搭載命令「call xmlrpc」がとことん使い物にならず、WordPressへの通信を行うとクラッシュすることを(ずいぶん昔に)確認してあったため、、、かわりになる部品を地道に探してありました。

WordPressとのXML-RPCによる通信を行うmacOS用フレームワーク「wpxmlrpc」を見つけ、Xcode上でビルドしてAppleScriptから呼び出す実験を行い、このように実際の投稿に利用しています。Github上のドキュメントはたいへんに素っ気なく、そのままObjective-CのコードをAppleScriptに置き換えても動作しない程度の素朴すぎる内容でしたが、REST APIの呼び出しAppleScriptを参考に内容を類推してひととおり動作できるところまでこぎつけました。

–> wpxmlrpc.framework

AppleScript名:WordPress XML-RPC Frameworkのじっけん
— Created 2018-02-08 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "wpxmlrpc" –https://github.com/wordpress-mobile/wpxmlrpc

set aRes to callXMLRPC("http://piyocast.com/as/xmlrpc.php", "demo.addTwoNumbers", {2, 3}) of me
–>  5

set aRes to callXMLRPC("http://piyocast.com/as/xmlrpc.php", "mt.supportedMethods", {}) of me
–>  {​​​​​"wp.getUsersBlogs", ​​​​​​​"wp.newPost", ​​​​​​​"wp.editPost", ​​​​​​​"wp.deletePost", ​​​​​​​"wp.getPost", ​​​​​​​"wp.getPosts", ​​​​​​​"wp.newTerm", ​​​​​​​"wp.editTerm", ​​​​​​​"wp.deleteTerm", ​​​​​​​"wp.getTerm", ​​​​​​​"wp.getTerms", ​​​​​​​"wp.getTaxonomy", ​​​​​​​"wp.getTaxonomies", ​​​​​​​"wp.getUser", ​​​​​​​"wp.getUsers", ​​​​​​​"wp.getProfile", ​​​​​​​"wp.editProfile", ​​​​​​​"wp.getPage", ​​​​​​​"wp.getPages", ​​​​​​​"wp.newPage", ​​​​​​​"wp.deletePage", ​​​​​​​"wp.editPage", ​​​​​​​"wp.getPageList", ​​​​​​​"wp.getAuthors", ​​​​​​​"wp.getCategories", ​​​​​​​"wp.getTags", ​​​​​​​"wp.newCategory", ​​​​​​​"wp.deleteCategory", ​​​​​​​"wp.suggestCategories", ​​​​​​​"wp.uploadFile", ​​​​​​​"wp.deleteFile", ​​​​​​​"wp.getCommentCount", ​​​​​​​"wp.getPostStatusList", ​​​​​​​"wp.getPageStatusList", ​​​​​​​"wp.getPageTemplates", ​​​​​​​"wp.getOptions", ​​​​​​​"wp.setOptions", ​​​​​​​"wp.getComment", ​​​​​​​"wp.getComments", ​​​​​​​"wp.deleteComment", ​​​​​​​"wp.editComment", ​​​​​​​"wp.newComment", ​​​​​​​"wp.getCommentStatusList", ​​​​​​​"wp.getMediaItem", ​​​​​​​"wp.getMediaLibrary", ​​​​​​​"wp.getPostFormats", ​​​​​​​"wp.getPostType", ​​​​​​​"wp.getPostTypes", ​​​​​​​"wp.getRevisions", ​​​​​​​"wp.restoreRevision", ​​​​​​​"blogger.getUsersBlogs", ​​​​​​​"blogger.getUserInfo", ​​​​​​​"blogger.getPost", ​​​​​​​"blogger.getRecentPosts", ​​​​​​​"blogger.newPost", ​​​​​​​"blogger.editPost", ​​​​​​​"blogger.deletePost", ​​​​​​​"metaWeblog.newPost", ​​​​​​​"metaWeblog.editPost", ​​​​​​​"metaWeblog.getPost", ​​​​​​​"metaWeblog.getRecentPosts", ​​​​​​​"metaWeblog.getCategories", ​​​​​​​"metaWeblog.newMediaObject", ​​​​​​​"metaWeblog.deletePost", ​​​​​​​"metaWeblog.getUsersBlogs", ​​​​​​​"mt.getCategoryList", ​​​​​​​"mt.getRecentPostTitles", ​​​​​​​"mt.getPostCategories", ​​​​​​​"mt.setPostCategories", ​​​​​​​"mt.supportedMethods", ​​​​​​​"mt.supportedTextFilters", ​​​​​​​"mt.getTrackbackPings", ​​​​​​​"mt.publishPost", ​​​​​​​"pingback.ping", ​​​​​​​"pingback.extensions.getPingbacks", ​​​​​​​"demo.sayHello", ​​​​​​​"demo.addTwoNumbers"​​​​​}

on callXMLRPC(paramURL, aMethod, aParamList)
  set aURL to current application’s |NSURL|’s URLWithString:paramURL
  
set aReq to current application’s NSMutableURLRequest’s alloc()’s initWithURL:aURL
  
aReq’s setHTTPMethod:"POST"
  
  
set encoder to current application’s WPXMLRPCEncoder’s alloc()’s initWithMethod:aMethod andParameters:aParamList
  (
aReq’s setHTTPBody:(encoder’s dataEncodedWithError:(missing value)))
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aReq returningResponse:(reference) |error|:(missing value)
  
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set cRes to second item of resList
  
(* (NSHTTPURLResponse) <NSHTTPURLResponse: 0x6000000289a0> { URL: http://piyocast.com/as/xmlrpc.php } { status code: 200, headers {
Connection = close;
"Content-Type" = "text/xml; charset=UTF-8";
Date = "Wed, 07 Feb 2018 16:10:49 GMT";
Server = Apache;
"Transfer-Encoding" = Identity;
} } *)
  
  
set decoder to current application’s WPXMLRPCDecoder’s alloc()’s initWithData:bRes
  
set errF to (decoder’s isFault()) as boolean
  
  
if errF = true then
    —Error
    
set xmlRPCres to faultCode of resStr
    
set xmlRPCbody to faultString of resStr
    
    
return false
  else
    –Success?
    
set xmlRPCres to (decoder’s object()) as list of string or string
    
    
–Error
    
if xmlRPCres = missing value then return false
  end if
  
  
return xmlRPCres
  
end callXMLRPC

★Click Here to Open This Script 

Posted in Internet Network XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy | 2 Comments

Post navigation

  • Older posts
  • Newer posts

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • UI Browserがgithub上でソース公開され、オープンソースに
  • macOS 13 TTS Voice環境に変更
  • Xcode 14.2でAppleScript App Templateを復活させる
  • 2022年に書いた価値あるAppleScript
  • ChatGPTで文章のベクトル化(Embedding)
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた
  • 従来と異なるmacOS 13の性格?
  • 新発売:CotEditor Scripting Book with AppleScript
  • macOS 13対応アップデート:AppleScript実践的テクニック集(1)GUI Scripting
  • AS関連データの取り扱いを容易にする(はずの)privateDataTypeLib
  • macOS 13でNSNotFoundバグふたたび
  • macOS 12.5.1、11.6.8でFinderのselectionでスクリーンショット画像をopenできない問題
  • ChatGPTでchatに対する応答文を取得
  • 新発売:iWork Scripting Book with AppleScript
  • Finderの隠し命令openVirtualLocationが発見される
  • macOS 13.1アップデートでスクリプトエディタの挙動がようやくまともに
  • あのコン過去ログビューワー(暫定版)

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (185) 13.0savvy (55) CotEditor (60) Finder (47) iTunes (19) Keynote (98) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (41) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (117) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (56) Pages (37) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKUserScriptInjectionTimeAtDocumentEnd (18) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • Clipboard
  • Code Sign
  • Color
  • Custom Class
  • dialog
  • drive
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • PDF
  • Peripheral
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC