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

カテゴリー: REST API

ニュースサイト ごちゃまぜフィード

Posted on 3月 3, 2018 by Takaaki Naganoya

ApitoreのREST API「ニュースサイト ごちゃまぜフィード」を呼び出して、さまざまなテック系サイトのNews Feedを一括で取得するAppleScriptです。

# Apitoreは2019年5月31日をもってサービスを終了

「ニュースサイト ごちゃまぜフィード」は、30分に1回の頻度でRSSの更新を確認にいきます。REST APIで最新情報が取得できるオンラインクローラーです。以下のサイトのRSSを収集しています。

・Huffington Post Japan
・IBTimes エンタメ・スポーツ
・IBTimes グローバル
・IBTimes マーケット
・IBTimes ライフ
・IBTimes 企業
・IBTimes 経済
・IBTimes IT・サイエンス
・ダイヤモンド・オンライン
・ビジネスジャーナル
・東洋経済オンライン
・毎日新聞
・CNN

本AppleScript利用のためには、Apitoreにサインアップしてアカウントを作成し、新規プロジェクトを作成(Test AppleScriptとか)。そこに、本APIを利用できるように登録し、「アクセストークン」を取得する必要があります。

アクセストークンを取得せずに掲載状態のまま本AppleScriptを実行してもエラーになります。

取得したアクセストークンを本AppleScript中のretAccessToken()ハンドラ内に記載し、実行してください。

AppleScript名:ニュースサイト ごちゃまぜフィード
— Created 2016-10-27 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

getNewsFeed() of me

on getNewsFeed()
  set allFeeds to {}
  
  
repeat with i from 1 to 100
    set {aRes, maxNum} to getAFeeds(i) of me
    
    
if aRes = false then exit repeat
    
set maxNum to maxNum as number
    
set allFeeds to allFeeds & aRes
    
if (maxNum div 10) ≤ i then
      exit repeat
    end if
  end repeat
  
  
return allFeeds
end getNewsFeed

on getAFeeds(aNum)
  set reqURLStr to "https://api.apitore.com/api/34/feeds/news"
  
set accessToken to retAccessToken() of me —Access Token
  
set aRec to {access_token:accessToken, page:(aNum as string)}
  
set aURL to retURLwithParams(reqURLStr, aRec) of me
  
  
set aRes to callRestGETAPIAndParseResults(aURL) of me
  
  
set aRESCode to (responseCode of aRes) as integer
  
if aRESCode is not equal to 200 then return {false, false}
  
  
set aRESTres to (json of aRes) as record
  
  
set sentiRes to entries of aRESTres
  
set allNum to num of aRESTres
  
–log allNum
  
  
return {sentiRes, allNum}
end getAFeeds

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
aRequest’s setValue:"gzip" forHTTPHeaderField:"Content-Encoding"
  
aRequest’s setValue:"Test AppleScript (gzip)" forHTTPHeaderField:"User-Agent"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
  
end callRestGETAPIAndParseResults

on retURLwithParams(aBaseURL, aRec)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

on retAccessToken()
  return "xxXXXxxX-XxXx-XXXX-xXXX-XXxXXxxXxxXx" –API Tore Access Token
end retAccessToken

★Click Here to Open This Script 

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

テックサイト ごちゃまぜフィード

Posted on 3月 3, 2018 by Takaaki Naganoya

ApitoreのREST API「テックサイト ごちゃまぜフィード」を呼び出して、さまざまなテック系サイトのNews Feedを一括で取得するAppleScriptです。

# Apitoreは2019年5月31日をもってサービスを終了

「テックサイト ごちゃまぜフィード」は、30分に1回の頻度でRSSの更新を確認にいきます。REST APIで最新情報が取得できるオンラインクローラーです。

本AppleScript利用のためには、Apitoreにサインアップしてアカウントを作成し、新規プロジェクトを作成(Test AppleScriptとか)。そこに、本APIを利用できるように登録し、「アクセストークン」を取得する必要があります。

アクセストークンを取得せずに掲載状態のまま本AppleScriptを実行してもエラーになります。

取得したアクセストークンを本AppleScript中のretAccessToken()ハンドラ内に記載し、実行してください。

AppleScript名:テックサイト ごちゃまぜフィード
— Created 2016-10-27 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set allFeeds to {}

repeat with i from 1 to 100
  set {aRes, maxNum} to getAFeeds(i) of me
  
  
if aRes = false then exit repeat
  
set maxNum to maxNum as number
  
set allFeeds to allFeeds & aRes
  
if (maxNum div 10) ≤ i then
    exit repeat
  end if
end repeat

return allFeeds
–>  
(*
{​​​​​{​​​​​​​author:"Ittousai", ​​​​​​​sourceTitle:"Engadget Japanese RSS Feed", ​​​​​​​title:" 速報:サムスンGalaxy S8発表イベント UNPACKED 2017 (ライブ更新ページ)
", ​​​​​​​link:"http://japanese.engadget.com/2017/03/29/galaxy-s8-unpacked-2017/", ​​​​​​​pubDate:1.49079606E+12, ​​​​​​​description:"<p> <img src=\"http://o.aolcdn.com/hss/storage/midas/a009a6b57896291f7e66fe091c6bdf94/205070326/unbox.png\" /> </p>", ​​​​​​​sourceLink:"http://japanese.engadget.com/rss.xml"​​​​​}, ​​​​​
*)

on getAFeeds(aNum)
  set reqURLStr to "https://api.apitore.com/api/35/feeds/tech"
  
set accessToken to retAccessToken() of me —Access Token
  
set aRec to {access_token:accessToken, page:(aNum as string)}
  
set aURL to retURLwithParams(reqURLStr, aRec) of me
  
  
set aRes to callRestGETAPIAndParseResults(aURL) of me
  
  
set aRESCode to (responseCode of aRes) as integer
  
if aRESCode is not equal to 200 then return {false, false}
  
  
set aRESTres to (json of aRes) as record
  
  
set sentiRes to entries of aRESTres
  
set allNum to num of aRESTres
  
log allNum
  
  
return {sentiRes, allNum}
end getAFeeds

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
aRequest’s setValue:"gzip" forHTTPHeaderField:"Content-Encoding"
  
aRequest’s setValue:"Test AppleScript (gzip)" forHTTPHeaderField:"User-Agent"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
  
end callRestGETAPIAndParseResults

on retURLwithParams(aBaseURL, aRec)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

on retAccessToken()
  return "xxXXXxxX-XxXx-XXXX-xXXX-XXxXXxxXxxXx" –API Tore Access Token
end retAccessToken

★Click Here to Open This Script 

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

RSS2JSON

Posted on 3月 3, 2018 by Takaaki Naganoya

ApitoreのREST API「RSS2JSON」を呼び出して、さまざまな種類のRSS(RSS0.9、RSS1.0、RSS2.0、Atomなど)をJSONに変換し、AppleScriptのrecord(record in list)オブジェクトに変換するAppleScriptです。

# Apitoreは2019年5月31日をもってサービスを終了

Language-Detectionは、テキストの言語判定を行います。検索機能に言語の絞り込みを付けたい場合や、テキストに対して言語別の処理をしたい場合に利用します。

本AppleScript利用のためには、Apitoreにサインアップしてアカウントを作成し、新規プロジェクトを作成(Test AppleScriptとか)。そこに、本APIを利用できるように登録し、「アクセストークン」を取得する必要があります。

アクセストークンを取得せずに掲載状態のまま本AppleScriptを実行してもエラーになります。

取得したアクセストークンを本AppleScript中のretAccessToken()ハンドラ内に記載し、実行してください。

AppleScript名:RSS2JSON
— Created 2016-10-27 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
–use keychainLib : script "keychainLib"

set rssURL to "http://piyocast.com/as/feed/"

set reqURLStr to "https://api.apitore.com/api/28/rome/rss2json"
–set accessToken to getPasswordForAccount("apitore API Key", "maro@piyocast.com") of keychainLib
set accessToken to retAccessToken() of me —Access Token

set aRec to {access_token:accessToken, rss:rssURL}
set aURL to retURLwithParams(reqURLStr, aRec) of me

set aRes to callRestGETAPIAndParseResults(aURL) of me

set aRESCode to (responseCode of aRes) as integer
if aRESCode is not equal to 200 then return {false, false}

set aRESTres to (json of aRes) as list of string or string –as anything
–> {|description|:"Useful & Practical AppleScript archive", author:missing value, link:"http://piyocast.com/as", |log|:"", pubDate:1.520068773E+12, title:"AppleScript Hole", entries:{{author:"Takaaki Naganoya", title:"(GET)国土地理院APIで現在位置の標高を取得する", pubDate:1.519998541E+12, |description|:"<p>国土地理院のREST API「標高API」を呼んで、現在位置の標高を取得するAppleScriptです。 現在位置の取得のためにMac本体のWiFiがオンになっている必要があります。 AppleScript名:(GET) &#8230; <a href=\"http://piyocast.com/as/archives/2545\" class=\"more-link\"><span class=\"screen-reader-text\">\"(GET)国土地理院APIで現在位置の標高を取得する\"の</span>続きを読む</a></p><p>投稿 <a rel=\"nofollow\" href=\"http://piyocast.com/as/archives/2545\">(GET)国土地理院APIで現在位置の標高を取得する</a> は <a rel=\"nofollow\" href=\"http://piyocast.com/as\">AppleScript Hole</a> に最初に表示されました。</p>", link:"http://piyocast.com/as/archives/2545"}, ….

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
–aRequest’s setValue:"gzip" forHTTPHeaderField:"Content-Encoding"
  
–aRequest’s setValue:"Test AppleScript (gzip)" forHTTPHeaderField:"User-Agent"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
  
end callRestGETAPIAndParseResults

on retURLwithParams(aBaseURL, aRec)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

on retAccessToken()
  return "xxXXXxxX-XxXx-XXXX-xXXX-XXxXXxxXxxXx" –API Tore Access Token
end retAccessToken

★Click Here to Open This Script 

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

(GET)国土地理院APIで現在位置の標高を取得する

Posted on 3月 2, 2018 by Takaaki Naganoya

国土地理院のREST API「標高API」を呼んで、現在位置の標高を取得するAppleScriptです。

現在位置の取得のためにMac本体のWiFiがオンになっている必要があります。

AppleScript名:(GET)国土地理院APIで現在位置の標高を取得する
— Created 2016-10-29 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "CoreLocation"
use framework "CoreWLAN"
–http://maps.gsi.go.jp/development/api.html

property locationManager : missing value
property curLatitude : 0
property curLongitude : 0

set reqURLStr to "http://cyberjapandata2.gsi.go.jp/general/dem/scripts/getelevation.php"

–現在地の緯度、経度情報を取得する
set {aLat, aLong} to getCurrentLocation() of me

set aRec to {lon:aLong as string, lat:aLat as string, outtype:"JSON"}
set aURL to retURLwithParams(reqURLStr, aRec) of me
set aRes to callRestGETAPIAndParseResults(aURL) of me

set aRESTres to (json of aRes) as record
return aRESTres
–>  {​​​​​hsrc:"5m(レーザ)", ​​​​​elevation:40.4​​​}

–set aRESCode to responseCode of aRes
–>  200

–set aRESHeader to responseHeader of aRes
–>  {​​​​​Server:"Apache/2.4.10 (Debian) PHP/5.6.19", ​​​​​Content-Type:"application/json; charset=utf-8", ​​​​​X-Powered-By:"PHP/5.6.19", ​​​​​Connection:"Keep-Alive", ​​​​​Access-Control-Allow-Origin:"*", ​​​​​Date:"Sat, 29 Oct 2016 10:53:14 GMT", ​​​​​Content-Encoding:"gzip", ​​​​​Content-Length:"71", ​​​​​Keep-Alive:"timeout=5, max=100", ​​​​​Vary:"Accept-Encoding"​​​}

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
  
end callRestGETAPIAndParseResults

on retURLwithParams(aBaseURL, aRec)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

on urlencodeStr(aStr)
  set aString to current application’s NSString’s stringWithString:aStr
  
set aString to (aString’s stringByAddingPercentEncodingWithAllowedCharacters:(current application’s NSCharacterSet’s URLQueryAllowedCharacterSet())) as text
  
return aString
end urlencodeStr

on getCurrentLocation()
  activeWiFiPower() of me
  
  
set locationManager to current application’s CLLocationManager’s alloc()’s init()
  
  
set locE to locationManager’s locationServicesEnabled()
  
if (locE as boolean) = true then
    locationManager’s setDelegate:me
    
locationManager’s setDesiredAccuracy:(current application’s kCLLocationAccuracyNearestTenMeters)
    
locationManager’s setDistanceFilter:500
    
locationManager’s startUpdatingLocation()
  else
    return false –error in init
  end if
  
  
set hitF to false
  
repeat 3000 times
    if {curLatitude, curLongitude} is not equal to {0, 0} then
      set hitF to true
      
exit repeat
    end if
    
delay 0.01
  end repeat
  
  
if hitF = false then return false
  
return {curLatitude, curLongitude}
  
end getCurrentLocation

—-以下、curLocationLibの内容

on locationManager:manager didUpdateLocations:locations
  
  
–Listing 1-3 Processing an incoming location event
  
set location to (locations’s lastObject())
  
set eventDate to (location’s timestamp())
  
set howRecent to (eventDate’s timeIntervalSinceNow())
  
  
–Calc ABS
  
set howRecent to howRecent as real
  
set howRecent to absNum(howRecent)
  
log howRecent
  
  
if howRecent < 15.0 then
    
    
set alt to location’s altitude
    
–>  (NSNumber) 46.356517791748
    
    
set aSpeed to location’s speed
    
–>  (NSNumber) -1.0
    
    
set aCourse to location’s course –North:0, East:90, South:180, West:270
    
–>  (NSNumber) -1.0
    
    
–By Shane Stanley
    
set theDescription to location’s |description|()
    
–> (NSString) "<+35.xxxxx,+139.xxxxxx> +/- 65.00m (speed -1.00 mps / course -1.00) @ 2015/03/04 8時56分41秒 日本標準時"
    
    
set anNSScanner to current application’s NSScanner’s scannerWithString:theDescription
    
anNSScanner’s setCharactersToBeSkipped:(current application’s NSCharacterSet’s characterSetWithCharactersInString:"<,")
    
set {theResult, aLat} to anNSScanner’s scanDouble:(reference)
    
set {theResult, aLng} to anNSScanner’s scanDouble:(reference)
    
    
copy {aLat, aLng} to {my curLatitude, my curLongitude}
    
  else
    log {"stopUpdatingLocation"}
    
locationManager’s stopUpdatingLocation()
  end if
  
end locationManager:didUpdateLocations:

on locationManager:anCLLocationManager didFailWithError:anNSError
  display dialog (anNSError’s localizedDescription() as text)
end locationManager:didFailWithError:

on absNum(aNum)
  if aNum > 0 then
    return aNum
  else
    return (aNum * -1)
  end if
end absNum

—Activate WiFi Power

on activeWiFiPower()
  set dName to getWiFiDeviceName() of me
  
set aInterface to current application’s CWInterface’s alloc()’s initWithInterfaceName:dName
  
set aPowerStat to (aInterface’s powerOn()) as boolean
  
if aPowerStat = false then
    set wRes to aInterface’s setPower:true |error|:(missing value)
    
if wRes = missing value then
      error "Can’t power on WiFi Interface."
    end if
  end if
end activeWiFiPower

–指定ハードウェアポートのデバイス名を取得する
on getWiFiDeviceName()
  set v2 to system attribute "sys2" –> 4
  
if v2 ≤ 6 then
    set hardWareName to "AirPort" –Under Mac OS X 10.6.8
    
set aMesStr to "Current AirPort Network: "
  else if v2 ≥ 7 then
    set hardWareName to "Wi-Fi" –Mac OS X 10.7 or later
    
set aMesStr to "Current Wi-Fi Network: "
  else
    display dialog "error"
  end if
  
  
set dName to getHardwareDeviceName(hardWareName) of me
  
return dName
end getWiFiDeviceName

–指定ハードウェアポートのデバイス名を取得する
on getHardwareDeviceName(targName)
  set sRes to do shell script "/usr/sbin/networksetup -listallhardwareports"
  
log sRes
  
set sList to paragraphs of sRes
  
set s1List to items 2 thru -1 of sList
  
  
set s2List to {}
  
repeat with i in s1List
    set j to contents of i
    
if j is equal to "VLAN Configurations" then
      exit repeat
    end if
    
set the end of s2List to j
  end repeat
  
  
–ネットワークポート関連のレコードを作成
  
set s3List to {}
  
set aLen to length of s2List
  
repeat with i from 1 to aLen by 4
    set a1Item to contents of item i of s2List
    
set a1Item to repChar(a1Item, "Hardware Port: ", "") of me
    
    
set a2Item to contents of item (i + 1) of s2List
    
set a2Item to repChar(a2Item, "Device: ", "") of me
    
    
set a3Item to contents of item (i + 2) of s2List
    
set a3Item to repChar(a3Item, "Ethernet Address: ", "") of me
    
    
set the end of s3List to {hardwarePort:a1Item, device:a2Item, ethernetAddress:a3Item}
  end repeat
  
  
repeat with i in s3List
    set j1 to hardwarePort of i
    
set j2 to device of i
    
if j1 is equal to targName then
      return j2
    end if
  end repeat
  
  
return ""
  
end getHardwareDeviceName

–文字置換ルーチン
on repChar(origText, targStr, repStr)
  set {txdl, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, targStr}
  
set temp to text items of origText
  
set AppleScript’s text item delimiters to repStr
  
set res to temp as text
  
set AppleScript’s text item delimiters to txdl
  
return res
end repChar

★Click Here to Open This Script 

Posted in geolocation Network REST API | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

じゃらんAPIで宿情報を検索する

Posted on 3月 2, 2018 by Takaaki Naganoya

じゃらんの宿表示 Web API経由でリクエストした宿泊情報を返すAppleScriptです。

利用のためには、じゃらんにアカウント登録を行い、アクセスキーを取得。取得したキーをretAccessKey()ハンドラ中に記入することが必要です。

AppleScript名:じゃらんAPIで宿情報を検索する
— Created 2016-11-20 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

–http://www.jalan.net/jw/jwp0100/jww0102.do

property dictStack : missing value — stack to hold array of dictionaries
property textInProgress : "" — string to collect text as it is found
property anError : missing value — if we get an error, store it here

set reqURLStr to "http://jws.jalan.net/APIAdvance/HotelSearch/V1/"

set aKey to retAccessKey() of me

–横浜みなとみらい地区で2016年11月21日宿泊の1室、大人2名で宿泊可能な施設
set aRec to {|key|:aKey, s_area:"140202", stay_date:"20180421", room_count:"1", adult_num:"2", sc_num:"0"}
–日付を「過去」に設定すると結果が返ってこない点に注意

set aURL to retURLwithParams(reqURLStr, aRec) of me
set aRes to callRestGETAPIAndParseResults(aURL) of me
set aRESCode to responseCode of aRes
if aRESCode is not equal to 200 then return false
set aRESHeader to responseHeader of aRes
set aXMLres to (xml of aRes)
set aNameRes to (aXMLres’s valueForKeyPath:"Results.Hotel.HotelName.contents") as list
–>  {"ホテルルートイン横浜馬車道", "ホテル エディット 横濱", "ホテル アイマーレ 横浜伊勢佐木町", "ホテルパセラの森 横浜関内", "横浜 マンダリンホテル", "ホテルモントレ横浜", "ヨコハマホステルヴィレッジ林会館", "スターホテル横浜", "アパホテル<横浜関内>", "リゾートカプセル桜木町(BBHホテルグループ)"}

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set aXmlRec to my makeRecordWithXML:resStr
  
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {xml:aXmlRec, responseCode:resCode, responseHeader:resHeaders}
end callRestGETAPIAndParseResults

on retURLwithParams(aBaseURL, aRec)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

on retAccessKey()
  return "xxxXXXXXXXXXxX" –じゃらんAPIキー
end retAccessKey

on urlencodeStr(aStr)
  set aString to current application’s NSString’s stringWithString:aStr
  
set aString to (aString’s stringByAddingPercentEncodingWithAllowedCharacters:(current application’s NSCharacterSet’s URLQueryAllowedCharacterSet())) as text
  
return aString
end urlencodeStr

——–XMLParse Lib

on makeRecordWithXML:xmlString
  set my dictStack to current application’s NSMutableArray’s array() — empty mutable array
  
set anEmpty to current application’s NSMutableDictionary’s |dictionary|()
  (
my dictStack)’s addObject:anEmpty — add empty mutable dictionary
  
set my textInProgress to current application’s NSMutableString’s |string|() — empty mutable string
  
  
set anNSString to current application’s NSString’s stringWithString:xmlString
  
set theData to anNSString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
  
set theNSXMLParser to current application’s NSXMLParser’s alloc()’s initWithData:theData
  
  
theNSXMLParser’s setDelegate:me
  
  
set theResult to theNSXMLParser’s parse()
  
if theResult then — went OK, get first item on stack
    return ((my dictStack)’s firstObject()) –as record
  else
    error (my anError’s localizedDescription() as text)
  end if
end makeRecordWithXML:

— this is an XML parser delegate method. Called when new element found
on parser:anNSXMLParser didStartElement:elementName namespaceURI:aString qualifiedName:qName attributes:aRecord
  set parentDict to my dictStack’s lastObject()
  
set childDict to current application’s NSMutableDictionary’s |dictionary|()
  
if aRecord’s |count|() > 0 then
    childDict’s setValue:aRecord forKey:"attributes"
  end if
  
  
set existingValue to parentDict’s objectForKey:elementName
  
  
if existingValue is not missing value then
    if (existingValue’s isKindOfClass:(current application’s NSMutableArray)) as boolean then
      set theArray to existingValue
    else
      set theArray to current application’s NSMutableArray’s arrayWithObject:existingValue
      
parentDict’s setObject:theArray forKey:elementName
    end if
    
    
theArray’s addObject:childDict
  else
    parentDict’s setObject:childDict forKey:elementName
  end if
  
  (
my dictStack)’s addObject:childDict
end parser:didStartElement:namespaceURI:qualifiedName:attributes:

— this is an XML parser delegate method. Called at the end of an element
on parser:anNSXMLParser didEndElement:elementName namespaceURI:aString qualifiedName:qName
  if my textInProgress’s |length|() > 0 then
    set dictInProgress to my dictStack’s lastObject()
    
dictInProgress’s setObject:textInProgress forKey:"contents"
    
set my textInProgress to current application’s NSMutableString’s |string|()
  end if
  
  
my dictStack’s removeLastObject()
end parser:didEndElement:namespaceURI:qualifiedName:

— this is an XML parser delegate method. Called when string is found. May be called repeatedly
on parser:anNSXMLParser foundCharacters:aString
  if (aString’s stringByTrimmingCharactersInSet:(current application’s NSCharacterSet’s whitespaceAndNewlineCharacterSet()))’s |length|() > 0 then
    (my textInProgress)’s appendString:aString
  end if
end parser:foundCharacters:

— this is an XML parser delegate method. Called when there’s an error
on parser:anNSXMLParser parseErrorOccurred:anNSError
  set my anError to anNSError
end parser:parseErrorOccurred:

★Click Here to Open This Script 

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

Language Detection -53 languages- langdetect

Posted on 3月 2, 2018 by Takaaki Naganoya

ApitoreのREST API「Language Detection -53 languages-」を呼び出して、指定したテキストの言語(日本語とか英語とか)を推定するAppleScriptです。

# Apitoreは2019年5月31日をもってサービスを終了

Language-Detectionは、テキストの言語判定を行います。検索機能に言語の絞り込みを付けたい場合や、テキストに対して言語別の処理をしたい場合に利用します。

本AppleScript利用のためには、Apitoreにサインアップしてアカウントを作成し、新規プロジェクトを作成(Test AppleScriptとか)。そこに、本APIを利用できるように登録し、「アクセストークン」を取得する必要があります。

アクセストークンを取得せずに掲載状態のまま本AppleScriptを実行してもエラーになります。

取得したアクセストークンを本AppleScript中のretAccessToken()ハンドラ内に記載し、実行してください。

本REST APIを評価した感想は、言語判定可能なテキスト分量がやや長め(俳句や短歌程度だとダメ。Twitter投稿ぐらいの文字数があれば大丈夫)でありつつ、APIに突っ込める文字の長さに制限があるため、対象のテキストをすべて渡すのではなく、テキストの一部を抜粋して評価を行うのが適しているように思われました。

AppleScript名:Language Detection -53 languages- langdetect
— Created 2016-10-27 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set targStr to "This is a pen. This is an apple. This is applepen."

set reqURLStr to "https://api.apitore.com/api/22/langdetect/get"
set accessToken to retAccessToken() of me

set aRec to {access_token:accessToken, |text|:targStr}
set aURL to retURLwithParams(reqURLStr, aRec) of me

set aRes to callRestGETAPIAndParseResults(aURL) of me
set aRESCode to (responseCode of aRes)
set aRESTres to (json of aRes)

return aRESTres as list of string or string

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
  
end callRestGETAPIAndParseResults

on retAccessToken()
  return "xxXXXxxX-XxXx-XXXX-xXXX-XXxXXxxXxxXx" –API Tore Access Token
end retAccessToken

on retURLwithParams(aBaseURL, aRec)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

★Click Here to Open This Script 

Posted in Network REST API Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Wikipediaの任意の項目の本文に入っているURLがリンク切れになっていないかどうかチェック v2

Posted on 2月 27, 2018 by Takaaki Naganoya
AppleScript名:Wikipediaの任意の項目の本文に入っているURLがリンク切れになっていないかどうかチェック v2
— Created 2017-03-29 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
–https://www.mediawiki.org/wiki/API:Main_page/ja

set aKeyword to "AppleScript"

set aStr to getBody(aKeyword) of me

–ものすごく大甘な転送検出
if aStr begins with "#転送" then
  set bStr to detectForwarding(aStr) of me
  
–転送先のキーワードで再度処理
  
set aStr to getBody(bStr) of me
end if

set aRes to extractURLsAndValidateThem(aStr) of me
–>  {​​​​​safeURL:27, ​​​​​forwardedURL:19, ​​​​​brokenURL:0, ​​​​​brokenURLs:{}​​​}

on detectForwarding(aStr)
  if aStr begins with "#転送" then
    set aRes to parseByDelim(aStr, {"[[", "]]"}) of me
    
–>  {​​​​​"#転送 ", ​​​​​"MacOS", ​​​​​""​​​}
    
return item 2 of aRes –エラーチェックはやっていない。大甘
  else
    return aStr
  end if
end detectForwarding

on extractURLsAndValidateThem(aStr)
  set urlList to extractLinksFromNaturalText(aStr) of me as list
  
  
set okList to {}
  
set fwList to {}
  
set ngList to {}
  
  
repeat with i in urlList
    set j to contents of i
    
set aTarg to j’s absoluteString() as string
    
set {exRes, headerRes, aData, resURL} to checkURLResourceExistence(j, 30) of me
    
    
if exRes = false then
      –URL取得時に連続するスペースをURLの一部として誤解して取得するケースがあるので、クリーニングしてリトライ  
      
set bStr to cleaningURLStr(aTarg) of me
      
      
if bStr = false then
        –クリーニング対象文字列がなかった。本当にダメだった
        
set the end of ngList to aTarg
      else
        –リトライ(タイムアウト条件も緩和)
        
set bURL to (current application’s |NSURL|’s URLWithString:bStr)
        
set {exRes, headerRes, aData, resURL} to checkURLResourceExistence(bURL, 60) of me
        
        
if exRes = false then
          –やっぱりダメでした。ごめんなさい(T_T)
          
set the end of ngList to bStr
        else if resURL is not equal to bStr then
          –URLがForwardされていた
          
set the end of fwList to bStr
        else
          –OKだった(リクエストしたURLとリプライURLが同じ、そこに何かの同名のファイルが存在した)
          
set the end of okList to bStr
        end if
        
      end if
      
    else if resURL is not equal to aTarg then
      –URLがForwardされていた
      
set the end of fwList to aTarg
    else
      –OKだった(リクエストしたURLとリプライURLが同じ、そこに何かの同名のファイルが存在した)
      
set the end of okList to aTarg
    end if
    
  end repeat
  
  
set resList to {safeURL:length of okList, forwardedURL:length of fwList, brokenURL:length of ngList, brokenURLs:ngList}
  
return resList
end extractURLsAndValidateThem

on cleaningURLStr(aStr)
  set anOffset to offset of "%20" in aStr
  
if anOffset = 0 then return false
  
set bStr to text 1 thru (anOffset – 1) of aStr
  
return bStr
end cleaningURLStr

on getBody(aKeyword)
  –set reqURLStr to "https://en.wikipedia.org/w/api.php"–English Version
  
set reqURLStr to "https://jp.wikipedia.org/w/api.php" –Japanese Version
  
  
set aRec to {action:"query", titles:aKeyword, |prop|:"revisions", rvprop:"content", |format|:"json"}
  
–set aRec to {action:"query", titles:"AppleScript|Mac OS X|Objective-C", |prop|:"revisions", rvprop:"content", |format|:"json"}
  
set aURL to retURLwithParams(reqURLStr, aRec) of me
  
set aRes to callRestGETAPIAndParseResults(aURL) of me
  
  
set aRESTres to (json of aRes)
  
–> {query:{pages:{2954:{pageid:2954, title:"AppleScript", revisions:{{contentformat:"text/x-wiki", *:"{{Infobox プログラミング言語|名前 = AppleScript ……., contentmodel:"wikitext"}}, ns:0}}}, batchcomplete:""}
  
  
–最初にヒットしたものだけを返す(同じ名前の項目が複数存在した場合でも)
  
set aRes to (aRESTres’s valueForKeyPath:"query.pages")
  
set aKeyStr to (aRes’s allKeys()’s firstObject()) as string
  
set aKeyPath to aKeyStr & ".revisions.*"
  
  
set aBody to (aRes’s valueForKeyPath:aKeyPath)’s firstObject() as string
  
return aBody
end getBody

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
end callRestGETAPIAndParseResults

on retURLwithParams(aBaseURL, aRec)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

on urlencodeStr(aStr)
  set aString to current application’s NSString’s stringWithString:aStr
  
set aString to (aString’s stringByAddingPercentEncodingWithAllowedCharacters:(current application’s NSCharacterSet’s URLQueryAllowedCharacterSet())) as text
  
return aString
end urlencodeStr

— 指定URLにファイル(画像など)が存在するかチェック
–> {存在確認結果(boolean), レスポンスヘッダー(NSDictionary), データ(NSData), 最終的なURLの文字列}
on checkURLResourceExistence(aURL, timeOutSec as real)
  set aRequest to (current application’s NSURLRequest’s requestWithURL:aURL cachePolicy:(current application’s NSURLRequestUseProtocolCachePolicy) timeoutInterval:timeOutSec)
  
set aRes to (current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value))
  
  
set dRes to (first item of (aRes as list))
  
set bRes to (second item of (aRes as list))
  
  
  
if bRes = missing value then
    set hRes to {}
    
set aResCode to -1 –error
    
return {false, hRes, dRes, missing value}
  else
    set resURL to ((|URL| of bRes)’s |absoluteURL|()’s absoluteString()) as string
  end if
  
–set resURL to ((|URL| of bRes)’s |absoluteURL|()’s absoluteString()) as string
  
  
if bRes is not equal to missing value then
    set hRes to (bRes’s allHeaderFields())
    
set aResCode to (bRes’s statusCode()) as integer
  else
    set hRes to {}
    
set aResCode to -1 –error
  end if
  
  
return {(aResCode = 200), hRes, dRes, resURL}
end checkURLResourceExistence

on extractLinksFromNaturalText(aString)
  set anNSString to current application’s NSString’s stringWithString:aString
  
  
set {theDetector, theError} to current application’s NSDataDetector’s dataDetectorWithTypes:(current application’s NSTextCheckingTypeLink) |error|:(reference)
  
  
set theMatches to theDetector’s matchesInString:anNSString options:0 range:{0, anNSString’s |length|()}
  
set theResults to theMatches’s valueForKey:"URL"
  
  
return theResults as list
end extractLinksFromNaturalText

on parseByDelim(aData, aDelim)
  set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to aDelim
  
set dList to text items of aData
  
set AppleScript’s text item delimiters to curDelim
  
return dList
end parseByDelim

★Click Here to Open This Script 

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

POST method REST API__Sendgrid_Send v1

Posted on 2月 26, 2018 by Takaaki Naganoya

メールの高速大量送信サービス「SendGrid」のREST API経由でメールの送信を行うAppleScriptです。

試用にあたっては、SendGridにサインアップして試用アカウントを取得してください。この試用アカウントで実運用を行わないことがアカウト取得の前提条件となっています(かなり念押しされました、、、)。

アクセストークンを取得したら、本リスト内のretAccessTokenハンドラ内にペーストしてください。本リストを掲載状態のままAccessTokenが伏字の状態で実行しても、メール送信は行えません。

気になるメールの転送速度ですが、本AppleScriptではだいたい1通あたり0.1秒程度です。Mail.app経由で一般的なプロバイダのメールサーバーを経由して送るよりは10倍程度高速ですが、APIの呼び方をチューニングすることで、さらにこの10倍ぐらいの高速送信は行えるようになります。

AppleScript名:POST method REST API__Sendgrid_Send v1
— Created 2017-05-23 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set a1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate()
repeat with i from 1 to 10
  set aSubject to "ぴよまるさんからの新しいおしらせ" & i as string
  
set aBody to "ぴよまるさんこんばんわ" & i as string
  
set toAddress to "maro@piyocast.com"
  
set fromAddress to "piyomarusoft@mac.com"
  
set aRes to sendMailViaSendGrid(aSubject, aBody, toAddress, fromAddress) of me
end repeat
set b1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate()
set c1Dat to (b1Dat – a1Dat) as real
return c1Dat

on sendMailViaSendGrid(aSubject, aBody, toAddress, fromAddress)
  set accessToken to "Bearer " & retAccessToken() —Access Token
  
set reqURLStr to "https://api.sendgrid.com/v3/mail/send"
  
set aRec to {personalizations:{{|to|:{{email:toAddress}}, subject:aSubject}}, |from|:{email:fromAddress, |name|:"ぴよ まるお"}, content:{{type:"text/plain", value:aBody}}}
  
set aRes to callRestPOSTAPIAndParseResults(reqURLStr, accessToken, aRec) of me
  
set aRESTres to json of aRes
  
set aRESCode to (responseCode of aRes) as integer
  
return (aRESCode = 202) –リクエスト成立ならtrueが返る( )
end sendMailViaSendGrid

–POST methodのREST APIを呼ぶ
on callRestPOSTAPIAndParseResults(aURL, anAPIkey, aRec)
  set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
aRequest’s setHTTPMethod:"POST"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:anAPIkey forHTTPHeaderField:"Authorization"
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Content-Type"
  
aRequest’s setValue:"gzip" forHTTPHeaderField:"Content-Encoding"
  
set dataJson to current application’s NSJSONSerialization’s dataWithJSONObject:aRec options:0 |error|:(missing value)
  
aRequest’s setHTTPBody:dataJson
  
  
–CALL REST API
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
  
–Parse Results
  
set resList to aRes as list
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code
  
set dRes to contents of second item of resList
  
set resCode to (dRes’s statusCode()) as integer
  
  
–Get Response Header
  
set resHeaders to (dRes’s allHeaderFields()) as record
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
end callRestPOSTAPIAndParseResults

on retAccessToken()
  return "XX.XxX_XXxxXXxxxxxxXxXXXx.xXXXxXXXxXXXxXXxXxxxXXXxXXxxxXXXXxxxXxXxXXx"
end retAccessToken

★Click Here to Open This Script 

Posted in JSON Network REST API | Tagged 10.11savvy 10.12savvy 10.13savvy Mail | Leave a comment

なろう小説APIで各カテゴリごとの集計を実行(大カテゴリのみ)

Posted on 2月 24, 2018 by Takaaki Naganoya

–> GZIP.framework

AppleScript名:なろう小説APIで各カテゴリごとの集計を実行(大カテゴリのみ)
— Created 2017-10-10 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "GZIP"
–https://github.com/nicklockwood/GZIP
–http://dev.syosetu.com/man/api/
–1日の利用上限は80,000または転送量上限400MByte???

property |NSURL| : a reference to current application’s |NSURL|
property NSString : a reference to current application’s NSString
property NSArray : a reference to current application’s NSArray
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding
property NSMutableDictionary : a reference to current application’s NSMutableDictionary
property NSURLQueryItem : a reference to current application’s NSURLQueryItem
property NSURLComponents : a reference to current application’s NSURLComponents
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property NSMutableURLRequest : a reference to current application’s NSMutableURLRequest
property NSURLConnection : a reference to current application’s NSURLConnection
property NSSortDescriptor : a reference to current application’s NSSortDescriptor
property NSNumber : a reference to current application’s NSNumber
property NSNumberFormatter : a reference to current application’s NSNumberFormatter
property NSNumberFormatterRoundUp : a reference to current application’s NSNumberFormatterRoundUp
property NSNumberFormatterRoundDown : a reference to current application’s NSNumberFormatterRoundDown

set invList to {}

set bgList to {1, 2, 3, 4, 99, 98}
set bigGnereLabel to {"恋愛", "ファンタジー", "文芸", "SF", "その他", "ノンジャンル"}

–全体の件数取得
set aRec to {gzip:"5", out:"json", lim:"1"}
set aRESTres to callNarouAPI(aRec, "1", "1") of me
set wholeCount to (allCount of first item of aRESTres)

–カテゴリごとの集計
repeat with i in bgList
  –repeat with ii in gList
  
set aRec to {gzip:"5", biggenre:i as string, out:"json", lim:"1"}
  
set aRESTres to callNarouAPI(aRec, "1", "1") of me
  
set aTotal to allCount of first item of aRESTres
  
  
if aTotal is not equal to 0 then
    set big to contents of i
    
set bigLabel to getLabelFromNum(bgList, bigGnereLabel, big) of me
    
set aPerCentatge to roundingDownNumStr(((aTotal / wholeCount) * 100), 1) of me
    
set the end of invList to {biggenre:bigLabel, totalNum:aTotal, percentage:aPerCentatge}
  end if
  
–end repeat
end repeat

set bList to sortRecListByLabel(invList, "totalNum", false) of me –降順ソート
–>  {​​​​​{​​​​​​​totalNum:274075, ​​​​​​​percentage:53.1, ​​​​​​​biggenre:"ノンジャンル"​​​​​}, ​​​​​{​​​​​​​totalNum:68890, ​​​​​​​percentage:13.3, ​​​​​​​biggenre:"文芸"​​​​​}, ​​​​​{​​​​​​​totalNum:68426, ​​​​​​​percentage:13.2, ​​​​​​​biggenre:"ファンタジー"​​​​​}, ​​​​​{​​​​​​​totalNum:46165, ​​​​​​​percentage:8.9, ​​​​​​​biggenre:"その他"​​​​​}, ​​​​​{​​​​​​​totalNum:45965, ​​​​​​​percentage:8.9, ​​​​​​​biggenre:"恋愛"​​​​​}, ​​​​​{​​​​​​​totalNum:11733, ​​​​​​​percentage:2.2, ​​​​​​​biggenre:"SF"​​​​​}​​​}

on callNarouAPI(aRec, callFrom, callNum)
  set reqURLStr to "http://api.syosetu.com/novelapi/api/" –通常API
  
  
–set aRec to {gzip:"5", |st|:callFrom as string, out:"json", lim:callNum as string}
  
set aURL to retURLwithParams(reqURLStr, aRec) of me
  
set aRes to callRestGETAPIAndParseResults(aURL) of me
  
  
set aRESCode to (responseCode of aRes) as integer
  
if aRESCode is not equal to 200 then return false
  
  
set aRESHeader to responseHeader of aRes
  
set aRESTres to (json of aRes) as list
  
end callNarouAPI

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  set aRequest to NSMutableURLRequest’s requestWithURL:(|NSURL|’s URLWithString:aURL)
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setValue:"gzip" forHTTPHeaderField:"Content-Encoding"
  
  
set aRes to NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
  
set rRes to bRes’s gunzippedData() –From GZIP.framework
  
  
set resStr to NSString’s alloc()’s initWithData:rRes encoding:(NSUTF8StringEncoding)
  
  
set jsonString to NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding)
  
set aJsonDict to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
end callRestGETAPIAndParseResults

on retURLwithParams(aBaseURL, aRec)
  set aDic to NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

–リストに入れたレコードを、指定の属性ラベルの値でソート
on sortRecListByLabel(aRecList as list, aLabelStr as string, ascendF as boolean)
  set aArray to NSArray’s arrayWithArray:aRecList
  
  
set sortDesc to NSSortDescriptor’s alloc()’s initWithKey:aLabelStr ascending:ascendF
  
set sortDescArray to NSArray’s arrayWithObjects:sortDesc
  
set sortedArray to aArray’s sortedArrayUsingDescriptors:sortDescArray
  
  
set bList to sortedArray as list
  
return bList
end sortRecListByLabel

on getLabelFromNum(aList, labelLIst, aNum)
  set aInd to offsetOf(aList, aNum) of me
  
set anItem to contents of item aInd of labelLIst
  
return anItem
end getLabelFromNum

on offsetOf(aList as list, aTarg)
  set aArray to current application’s NSArray’s arrayWithArray:aList
  
set aIndex to aArray’s indexOfObjectIdenticalTo:aTarg
  
return (aIndex + 1)
end offsetOf

on roundingDownNumStr(aNum as string, aDigit as integer)
  set a to NSString’s stringWithString:aNum
  
set aa to a’s doubleValue()
  
set aFormatter to NSNumberFormatter’s alloc()’s init()
  
aFormatter’s setMaximumFractionDigits:aDigit
  
aFormatter’s setRoundingMode:(NSNumberFormatterRoundDown)
  
set aStr to aFormatter’s stringFromNumber:aa
  
return (aStr as text) as real
end roundingDownNumStr

on roundingUpNumStr(aNum as string, aDigit as integer)
  set a to NSString’s stringWithString:aNum
  
set aa to a’s doubleValue()
  
set aFormatter to NSNumberFormatter’s alloc()’s init()
  
aFormatter’s setMaximumFractionDigits:aDigit
  
aFormatter’s setRoundingMode:(NSNumberFormatterRoundUp)
  
set aStr to aFormatter’s stringFromNumber:aa
  
return (aStr as text) as real
end roundingUpNumStr

★Click Here to Open This Script 

Posted in Network REST API | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

ip-apiでIPアドレスから場所を検索

Posted on 2月 16, 2018 by Takaaki Naganoya
AppleScript名:ip-apiでIPアドレスから場所を検索
— Created 2017-06-05 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set myIP to getGeoLocationByIPAIP("45.59.69.202") of me
–>  {lon:-75.5281, zip:"19801", query:"45.59.69.202", as:"AS3800 Ionity Corporation", countryCode:"US", isp:"Ionity Corporation", lat:39.7157, city:"Wilmington", region:"DE", timezone:"America/New_York", org:"Ionity Corporation", country:"United States", regionName:"Delaware", status:"success"}

–http://ip-api.com/docs/api:json
on getGeoLocationByIPAIP(myIP)
  set aURL to "http://ip-api.com/json/" & myIP
  
set aRes to callRestGETAPIAndParseResults(aURL) of me
  
set aRESTres to (json of aRes)
  
set aRESTcode to responseCode of aRes
  
if aRESTcode is not equal to 200 then return false
  
return aRESTres as record
end getGeoLocationByIPAIP

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as list of string or string
    
set resHeaders to (dRes’s allHeaderFields()) as list of string or string
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
end callRestGETAPIAndParseResults

★Click Here to Open This Script 

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

ipinfo.ioでIPアドレスから場所を検索

Posted on 2月 16, 2018 by Takaaki Naganoya
AppleScript名:ipinfo.ioでIPアドレスから場所を検索
— Created 2017-06-05 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set myIP to getGeoLocationByIPinfo("45.59.69.202") of me
–>  {​​​​​region:"Delaware", ​​​​​city:"Wilmington", ​​​​​country:"US", ​​​​​org:"AS3800 Talent House, Inc.", ​​​​​hostname:"No Hostname", ​​​​​postal:"19801", ​​​​​ip:"45.59.69.202", ​​​​​loc:"39.7157,-75.5281"​​​}

–http://ipinfo.io/developers
on getGeoLocationByIPinfo(myIP)
  set aURL to "http://ipinfo.io/" & myIP
  
set aRes to callRestGETAPIAndParseResults(aURL) of me
  
set aRESTres to (json of aRes)
  
set aRESTcode to responseCode of aRes
  
if aRESTcode is not equal to 200 then return false
  
return aRESTres as record
end getGeoLocationByIPinfo

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
aRequest’s setValue:"application/json" forHTTPHeaderField:"Accept"
  
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code & Header
  
set dRes to contents of second item of resList
  
if dRes is not equal to missing value then
    set resCode to (dRes’s statusCode()) as number
    
set resHeaders to (dRes’s allHeaderFields()) as record
  else
    set resCode to 0
    
set resHeaders to {}
  end if
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
end callRestGETAPIAndParseResults

★Click Here to Open This Script 

Posted in JSON Network REST API | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

freegeoipで指定IPアドレスの位置情報を取得

Posted on 2月 16, 2018 by Takaaki Naganoya
AppleScript名:freegeoipで指定IPアドレスの位置情報を取得
— Created 2017-12-20 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

property |NSURL| : a reference to current application’s |NSURL|
property NSData : a reference to current application’s NSData
property NSJSONSerialization : a reference to current application’s NSJSONSerialization

set aRes to getIPAddressInfoFreeGeoIP("91.108.183.75") of me as list of string or string –anything
–> {time_zone:"Europe/Stockholm", city:"", zip_code:"", longitude:18.056, metro_code:0, country_name:"Sweden", latitude:59.3247, country_code:"SE", region_code:"", region_name:"", |ip|:"91.108.183.75"}

–http://freegeoip.net
on getIPAddressInfoFreeGeoIP(IPAddress)
  try
    with timeout of 10 seconds
      set link to "http://freegeoip.net/json/" & IPAddress
      
set theURL to |NSURL|’s URLWithString:link
      
set jsonData to NSData’s dataWithContentsOfURL:theURL
      
set aJsonDict to (NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value))
      
return aJsonDict
    end timeout
  on error
    return missing value
  end try
end getIPAddressInfoFreeGeoIP

★Click Here to Open This Script 

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

Returns the value in BTC

Posted on 2月 16, 2018 by Takaaki Naganoya
AppleScript名:Returns the value in BTC
— Created 2017-12-24 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

property |NSURL| : a reference to current application’s |NSURL|
property NSData : a reference to current application’s NSData
property NSJSONSerialization : a reference to current application’s NSJSONSerialization

set aInfo to retValueInBTC("JPY", "10000") of me
–>  "0.00654764"

on retValueInBTC(aCurrency, aVal)
  set aRec to {currency:aCurrency, value:aVal}
  
set reqURLStr to "https://blockchain.info/tobtc"
  
set aURL to retURLwithParams(reqURLStr, aRec) of me
  
try
    with timeout of 10 seconds
      set curl_command to "curl " & quoted form of aURL
      
set jRes to do shell script curl_command
      
return jRes
    end timeout
  on error
    return missing value
  end try
end retValueInBTC

on retURLwithParams(aBaseURL, aRec)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

★Click Here to Open This Script 

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

Bitcoin Exchange Rates APIを呼び出す

Posted on 2月 16, 2018 by Takaaki Naganoya
AppleScript名:Bitcoin Exchange Rates APIを呼び出す
— Created 2017-12-11 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

property |NSURL| : a reference to current application’s |NSURL|
property NSData : a reference to current application’s NSData
property NSJSONSerialization : a reference to current application’s NSJSONSerialization

set aInfo to getBitcoinExchangeRating() of me as list of string or string
–> {​​​​​CNY:{​​​​​​​15m:85561.31, ​​​​​​​sell:85497.93, ​​​​​​​symbol:"¥", ​​​​​​​last:85561.31, ​​​​​​​buy:85624.69​​​​​}, ​​​​​PLN:{​​​​​​​15m:45977.18, ​​​​​​​sell:45943.12, ​​​​​​​symbol:"zł", ​​​​​​​last:45977.18, ​​​​​​​buy:46011.23​​​​​}, ​​​​​THB:{​​​​​​​15m:426039.93, ​​​​​​​sell:425724.34, ​​​​​​​symbol:"฿", ​​​​​​​last:426039.93, ​​​​​​​buy:426355.52​​​​​}, ​​​​​AUD:{​​​​​​​15m:16863.96, ​​​​​​​sell:16851.47, ​​​​​​​symbol:"$", ​​​​​​​last:16863.96, ​​​​​​​buy:16876.45​​​​​}, ​​​​​CLP:{​​​​​​​15m:8071171.16, ​​​​​​​sell:8065192.44, ​​​​​​​symbol:"$", ​​​​​​​last:8071171.16, ​​​​​​​buy:8077149.89​​​​​}, ​​​​​SEK:{​​​​​​​15m:108311.42, ​​​​​​​sell:108231.19, ​​​​​​​symbol:"kr", ​​​​​​​last:108311.42, ​​​​​​​buy:108391.65​​​​​}, ​​​​​BRL:{​​​​​​​15m:43429.07, ​​​​​​​sell:43396.9, ​​​​​​​symbol:"R$", ​​​​​​​last:43429.07, ​​​​​​​buy:43461.24​​​​​}, ​​​​​DKK:{​​​​​​​15m:81673.5, ​​​​​​​sell:81613.0, ​​​​​​​symbol:"kr", ​​​​​​​last:81673.5, ​​​​​​​buy:81734.0​​​​​}, ​​​​​GBP:{​​​​​​​15m:9741.63, ​​​​​​​sell:9734.41, ​​​​​​​symbol:"£", ​​​​​​​last:9741.63, ​​​​​​​buy:9748.84​​​​​}, ​​​​​RUB:{​​​​​​​15m:759210.64, ​​​​​​​sell:758648.26, ​​​​​​​symbol:"RUB", ​​​​​​​last:759210.64, ​​​​​​​buy:759773.03​​​​​}, ​​​​​CHF:{​​​​​​​15m:12874.51, ​​​​​​​sell:12864.97, ​​​​​​​symbol:"CHF", ​​​​​​​last:12874.51, ​​​​​​​buy:12884.04​​​​​}, ​​​​​ISK:{​​​​​​​15m:1379204.64, ​​​​​​​sell:1378183.0, ​​​​​​​symbol:"kr", ​​​​​​​last:1379204.64, ​​​​​​​buy:1380226.29​​​​​}, ​​​​​SGD:{​​​​​​​15m:17490.64, ​​​​​​​sell:17477.68, ​​​​​​​symbol:"$", ​​​​​​​last:17490.64, ​​​​​​​buy:17503.6​​​​​}, ​​​​​EUR:{​​​​​​​15m:11399.17, ​​​​​​​sell:11385.02, ​​​​​​​symbol:"€", ​​​​​​​last:11399.17, ​​​​​​​buy:11413.33​​​​​}, ​​​​​NZD:{​​​​​​​15m:18527.65, ​​​​​​​sell:18513.92, ​​​​​​​symbol:"$", ​​​​​​​last:18527.65, ​​​​​​​buy:18541.37​​​​​}, ​​​​​USD:{​​​​​​​15m:13013.82, ​​​​​​​sell:13004.18, ​​​​​​​symbol:"$", ​​​​​​​last:13013.82, ​​​​​​​buy:13023.46​​​​​}, ​​​​​TWD:{​​​​​​​15m:389815.96, ​​​​​​​sell:389527.21, ​​​​​​​symbol:"NT$", ​​​​​​​last:389815.96, ​​​​​​​buy:390104.72​​​​​}, ​​​​​KRW:{​​​​​​​15m:14025514.37, ​​​​​​​sell:14015124.95, ​​​​​​​symbol:"₩", ​​​​​​​last:14025514.37, ​​​​​​​buy:14035903.78​​​​​}, ​​​​​JPY:{​​​​​​​15m:1474075.39, ​​​​​​​sell:1472983.47, ​​​​​​​symbol:"¥", ​​​​​​​last:1474075.39, ​​​​​​​buy:1475167.31​​​​​}, ​​​​​INR:{​​​​​​​15m:833116.13, ​​​​​​​sell:832498.99, ​​​​​​​symbol:"₹", ​​​​​​​last:833116.13, ​​​​​​​buy:833733.26​​​​​}, ​​​​​HKD:{​​​​​​​15m:101728.97, ​​​​​​​sell:101653.61, ​​​​​​​symbol:"$", ​​​​​​​last:101728.97, ​​​​​​​buy:101804.32​​​​​}, ​​​​​CAD:{​​​​​​​15m:16568.51, ​​​​​​​sell:16556.23, ​​​​​​​symbol:"$", ​​​​​​​last:16568.51, ​​​​​​​buy:16580.78​​​​​}​​​}

set aVal to (aInfo’s valueForKeyPath:"JPY") as list of string or string
–> {​​​​​15m:1483814.35, ​​​​​sell:1483366.93, ​​​​​symbol:"¥", ​​​​​last:1483814.35, ​​​​​buy:1484261.76​​​}

on getBitcoinExchangeRating()
  try
    with timeout of 10 seconds
      set link to "https://blockchain.info/ticker" –Exchange Rates API
      
set theURL to |NSURL|’s URLWithString:link
      
set jsonData to NSData’s dataWithContentsOfURL:theURL
      
set aJsonDict to (NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value))
      
return aJsonDict
    end timeout
  on error
    return missing value
  end try
end getBitcoinExchangeRating

★Click Here to Open This Script 

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

GET method REST API_Anime API_getInfo_in_a_year_and_cour v2

Posted on 2月 16, 2018 by Takaaki Naganoya
AppleScript名:GET method REST API_Anime API_getInfo_in_a_year_and_cour v2
— Created 2016-05-11 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aYear to 2018
set aCour to 1

set reqURLStr to "http://api.moemoe.tokyo/anime/v1/master/" & (aYear as string) & "/" & (aCour as string)

set aRes to callRestGETAPIAndParseResults(reqURLStr) of me

set aRESTres to json of aRes
set aRESCode to responseCode of aRes
–>  200
set aRESHeader to (responseHeader of aRes) as list of string or string
–>  {Connection:"keep-alive", Access-Control-Allow-Origin:"*", Content-Type:"application/json; charset=utf-8", Content-Length:"353", Server:"nginx/1.8.0", Date:"Wed, 11 May 2016 01:14:49 GMT"}

return aRESTres as list of string or string
–>  (NSArray) {​​​​​{​​​​​​​id:281, ​​​​​​​title_short3:"", ​​​​​​​sex:0, ​​​​​​​sequel:0, ​​​​​​​created_at:"2016-01-01 23:40:06.0", ​​​​​​​public_url:"http://gundam-tb.net/", ​​​​​​​twitter_hash_tag:"gundam_tb", ​​​​​​​title:"機動戦士ガンダム サンダーボルト", ​​​​​​​updated_at:"2016-01-01 23:40:06.0", ​​​​​​​twitter_account:"gundam_tb", ​​​​​​​title_short1:"サンダーボルト", ​​​​​​​title_short2:"", ​​​​​​​cours_id:9​​​​​}, …….

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  –Request  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
  
–CALL REST API
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
  
–Parse Results
  
set resList to aRes as list
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code
  
set dRes to contents of second item of resList
  
set resCode to (dRes’s statusCode()) as list of string or string
  
  
–Get Response Header
  
set resHeaders to (dRes’s allHeaderFields()) as list of string or string
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
end callRestGETAPIAndParseResults

★Click Here to Open This Script 

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

GET method REST API_Anime API_getInfo_in_a_year v2

Posted on 2月 16, 2018 by Takaaki Naganoya
AppleScript名:GET method REST API_Anime API_getInfo_in_a_year v2
— Created 2016-05-11 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set reqURLStr to "http://api.moemoe.tokyo/anime/v1/master/" & "2016"

set aRes to callRestGETAPIAndParseResults(reqURLStr) of me

set aRESTres to json of aRes
set aRESCode to responseCode of aRes
–>  200
set aRESHeader to (responseHeader of aRes) as list of string or string –as anything
–>  {Connection:"keep-alive", Access-Control-Allow-Origin:"*", Content-Type:"application/json; charset=utf-8", Content-Length:"353", Server:"nginx/1.8.0", Date:"Wed, 11 May 2016 01:14:49 GMT"}

return aRESTres as list of string or string
–>  {​​​​​{​​​​​​​id:281, ​​​​​​​title:"機動戦士ガンダム サンダーボルト"​​​​​}, ​​​​​{​​​​​​​id:282, ​​​​​​​title:"プリンス・オブ・ストライド オルタナティブ"​​​​​}, ​​​​​{​​​​​​​id:283, ​​​​​​​title:"無彩限のファントム・ワールド"​​​​​}, ​​​​​{​​​​​​​id:284, ​​​​​​​title:"ハルチカ〜ハルタとチカは青春する〜"​​​​​}, ​​​​​{​​​​​​​id:285, ​​​​​​​title:"ノルン+ノネット"​​​​​}, ​​​​​{​​​​​​​id:286, ​​​​​​​title:"アクティヴレイド -機動強襲室第八係-"​​​​​}, ​​​​​{​​​​​​​id:287, ​​​​​​​title:"少女たちは荒野を目指す"​​​​​}, ​​​​​{​​​​​​​id:288, ​​​​​​​title:"僕だけがいない街"​​​​​}, ​​​​​{​​​​​​​id:289, ​​​​​​​title:"おじさんとマシュマロ"​​​​​}, ​​​​​{​​​​​​​id:290, ​​​​​​​title:"ファンタシースターオンライン2 ジ アニメーション"​​​​​}, ​​​​​{​​​​​​​id:291, ​​​​​​​title:"だがしかし"​​​​​}, ​​​​​{​​​​​​​id:292, ​​​​​​​title:"暗殺教室(第2期)"​​​​​}, ​​​​​{​​​​​​​id:293, ​​​​​​​title:"ディバインゲート"​​​​​}, ​​​​​{​​​​​​​id:294, ​​​​​​​title:"おしえて!ギャル子ちゃん"​​​​​}, ​​​​​{​​​​​​​id:295, ​​​​​​​title:"石膏ボーイズ"​​​​​}, ​​​​​{​​​​​​​id:296, ​​​​​​​title:"霊剣山 星屑たちの宴"​​​​​}, ​​​​​{​​​​​​​id:297, ​​​​​​​title:"GATE 自衛隊 彼の地にて、斯く戦えり(2期)"​​​​​}, ​​​​​{​​​​​​​id:298, ​​​​​​​title:"昭和元禄落語心中"​​​​​}, ​​​​​{​​​​​​​id:299, ​​​​​​​title:"紅殻のパンドラ"​​​​​}, ​​​​​{​​​​​​​id:300, ​​​​​​​title:"ブブキ・ブランキ"​​​​​}, ​​​​​{​​​​​​​id:301, ​​​​​​​title:"ラクエンロジック"​​​​​}, ​​​​​{​​​​​​​id:302, ​​​​​​​title:"デュラララ!!×2 結"​​​​​}, ​​​​​{​​​​​​​id:303, ​​​​​​​title:"ナースウィッチ小麦ちゃんR"​​​​​}, ​​​​​{​​​​​​​id:304, ​​​​​​​title:"虹色デイズ"​​​​​}, ​​​​​{​​​​​​​id:305, ​​​​​​​title:"大家さんは思春期!"​​​​​}, ​​​​​{​​​​​​​id:306, ​​​​​​​title:"Dimension W"​​​​​}, ​​​​​{​​​​​​​id:307, ​​​​​​​title:"灰と幻想のグリムガル"​​​​​}, ​​​​​{​​​​​​​id:308, ​​​​​​​title:"シュヴァルツェスマーケン"​​​​​}, ​​​​​{​​​​​​​id:309, ​​​​​​​title:"最弱無敗の神装機竜(バハムート)"​​​​​}, ​​​​​{​​​​​​​id:310, ​​​​​​​title:"赤髪の白雪姫(第2期)"​​​​​}, ​​​​​{​​​​​​​id:311, ​​​​​​​title:"てーきゅう(第7期)"​​​​​}, ​​​​​{​​​​​​​id:312, ​​​​​​​title:"魔法少女なんてもういいですから。"​​​​​}, ​​​​​{​​​​​​​id:313, ​​​​​​​title:"蒼の彼方のフォーリズム"​​​​​}, ​​​​​{​​​​​​​id:314, ​​​​​​​title:"この素晴らしい世界に祝福を!"​​​​​}, ​​​​​{​​​​​​​id:315, ​​​​​​​title:"亜人"​​​​​}, ​​​​​{​​​​​​​id:316, ​​​​​​​title:"FAIRY TAIL ZERO"​​​​​}, ​​​​​{​​​​​​​id:317, ​​​​​​​title:"ももくり"​​​​​}, ​​​​​{​​​​​​​id:318, ​​​​​​​title:"この男子、魔法がお仕事です。"​​​​​}, ​​​​​{​​​​​​​id:319, ​​​​​​​title:"SUSHI POLICE"​​​​​}, ​​​​​{​​​​​​​id:320, ​​​​​​​title:"血液型くん!4"​​​​​}, ​​​​​{​​​​​​​id:321, ​​​​​​​title:"迷家‐マヨイガ‐"​​​​​}, ​​​​​{​​​​​​​id:322, ​​​​​​​title:"宇宙パトロールルル子"​​​​​}, ​​​​​{​​​​​​​id:323, ​​​​​​​title:"機動戦士ガンダムユニコーン RE:0096"​​​​​}, ​​​​​{​​​​​​​id:324, ​​​​​​​title:"影鰐-KAGEWANI-承"​​​​​}, ​​​​​{​​​​​​​id:325, ​​​​​​​title:"ぼのぼの"​​​​​}, ​​​​​{​​​​​​​id:326, ​​​​​​​title:"フューチャーカード バディファイト トリプルディー"​​​​​}, ​​​​​{​​​​​​​id:327, ​​​​​​​title:"逆転裁判"​​​​​}, ​​​​​{​​​​​​​id:328, ​​​​​​​title:"学戦都市アスタリスク 2nd SEASON"​​​​​}, ​​​​​{​​​​​​​id:329, ​​​​​​​title:"僕のヒーローアカデミア"​​​​​}, ​​​​​{​​​​​​​id:330, ​​​​​​​title:"マクロス⊿"​​​​​}, ​​​​​{​​​​​​​id:331, ​​​​​​​title:"コンクリート・レボルティオ~超人幻想~THE LAST SONG"​​​​​}, ​​​​​{​​​​​​​id:332, ​​​​​​​title:"くまみこ"​​​​​}, ​​​​​{​​​​​​​id:333, ​​​​​​​title:"怪盗ジョーカー(シーズン3)"​​​​​}, ​​​​​{​​​​​​​id:334, ​​​​​​​title:"ばくおん!!"​​​​​}, ​​​​​{​​​​​​​id:335, ​​​​​​​title:"聖戦ケルベロス 竜刻のファタリテ"​​​​​}, ​​​​​{​​​​​​​id:336, ​​​​​​​title:"ハンドレッド"​​​​​}, ​​​​​{​​​​​​​id:337, ​​​​​​​title:"薄桜鬼~御伽草子~"​​​​​}, ​​​​​{​​​​​​​id:338, ​​​​​​​title:"ジョーカー・ゲーム"​​​​​}, ​​​​​{​​​​​​​id:339, ​​​​​​​title:"双星の陰陽師"​​​​​}, ​​​​​{​​​​​​​id:340, ​​​​​​​title:"SUPER LOVERS"​​​​​}, ​​​​​{​​​​​​​id:341, ​​​​​​​title:"鬼斬"​​​​​}, ​​​​​{​​​​​​​id:342, ​​​​​​​title:"文豪ストレイドッグス"​​​​​}, ​​​​​{​​​​​​​id:343, ​​​​​​​title:"あんハピ♪"​​​​​}, ​​​​​{​​​​​​​id:344, ​​​​​​​title:"クロムクロ"​​​​​}, ​​​​​{​​​​​​​id:345, ​​​​​​​title:"ネトゲの嫁は女の子じゃないと思った?"​​​​​}, ​​​​​{​​​​​​​id:346, ​​​​​​​title:"甲鉄城のカバネリ"​​​​​}, ​​​​​{​​​​​​​id:347, ​​​​​​​title:"少年メイド"​​​​​}, ​​​​​{​​​​​​​id:348, ​​​​​​​title:"坂本ですが?"​​​​​}, ​​​​​{​​​​​​​id:349, ​​​​​​​title:"田中くんはいつもけだるげ"​​​​​}, ​​​​​{​​​​​​​id:350, ​​​​​​​title:"キズナイーバー"​​​​​}, ​​​​​{​​​​​​​id:351, ​​​​​​​title:"はいふり"​​​​​}, ​​​​​{​​​​​​​id:352, ​​​​​​​title:"ふらいんぐうぃっち"​​​​​}, ​​​​​{​​​​​​​id:353, ​​​​​​​title:"とんかつDJアゲ太郎"​​​​​}, ​​​​​{​​​​​​​id:354, ​​​​​​​title:"三者三葉"​​​​​}, ​​​​​{​​​​​​​id:355, ​​​​​​​title:"うさかめ"​​​​​}, ​​​​​{​​​​​​​id:356, ​​​​​​​title:"マギ シンドバッドの冒険"​​​​​}, ​​​​​{​​​​​​​id:357, ​​​​​​​title:"Re:ゼロから始める異世界生活"​​​​​}, ​​​​​{​​​​​​​id:358, ​​​​​​​title:"うしおととら(第3クール)"​​​​​}, ​​​​​{​​​​​​​id:359, ​​​​​​​title:"ワガママハイスペック"​​​​​}, ​​​​​{​​​​​​​id:360, ​​​​​​​title:"ジョジョの奇妙な冒険 ダイヤモンドは砕けない"​​​​​}, ​​​​​{​​​​​​​id:361, ​​​​​​​title:"テラフォーマーズ リベンジ"​​​​​}, ​​​​​{​​​​​​​id:362, ​​​​​​​title:"プリパラ(3rdシーズン)"​​​​​}, ​​​​​{​​​​​​​id:363, ​​​​​​​title:"エンドライド"​​​​​}, ​​​​​{​​​​​​​id:364, ​​​​​​​title:"ビッグオーダー"​​​​​}​​​}

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  –Request  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
  
–CALL REST API
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
  
–Parse Results
  
set resList to aRes as list
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code
  
set dRes to contents of second item of resList
  
set resCode to (dRes’s statusCode()) as list of string or string –as anything
  
  
–Get Response Header
  
set resHeaders to (dRes’s allHeaderFields()) as list of string or string –as anything
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
end callRestGETAPIAndParseResults

★Click Here to Open This Script 

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

GET method REST API_Anime API_get cours v2

Posted on 2月 16, 2018 by Takaaki Naganoya
AppleScript名:GET method REST API_Anime API_get cours v2
— Created 2016-05-11 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set reqURLStr to "http://api.moemoe.tokyo/anime/v1/master/cours"

set aRes to callRestGETAPIAndParseResults(reqURLStr) of me

set aRESTres to json of aRes
set aRESCode to responseCode of aRes
–>  200
set aRESHeader to (responseHeader of aRes) as list of string or string
–>  {Connection:"keep-alive", Access-Control-Allow-Origin:"*", Content-Type:"application/json; charset=utf-8", Content-Length:"353", Server:"nginx/1.8.0", Date:"Wed, 11 May 2016 01:14:49 GMT"}

return aRESTres as list of string or string –as anything
–>   {​​​​​7:{​​​​​​​id:7, ​​​​​​​year:2015, ​​​​​​​cours:3​​​​​}, ​​​​​3:{​​​​​​​id:3, ​​​​​​​year:2014, ​​​​​​​cours:3​​​​​}, ​​​​​8:{​​​​​​​id:8, ​​​​​​​year:2015, ​​​​​​​cours:4​​​​​}, ​​​​​4:{​​​​​​​id:4, ​​​​​​​year:2014, ​​​​​​​cours:4​​​​​}, ​​​​​9:{​​​​​​​id:9, ​​​​​​​year:2016, ​​​​​​​cours:1​​​​​}, ​​​​​5:{​​​​​​​id:5, ​​​​​​​year:2015, ​​​​​​​cours:1​​​​​}, ​​​​​1:{​​​​​​​id:1, ​​​​​​​year:2014, ​​​​​​​cours:1​​​​​}, ​​​​​6:{​​​​​​​id:6, ​​​​​​​year:2015, ​​​​​​​cours:2​​​​​}, ​​​​​10:{​​​​​​​id:10, ​​​​​​​year:2016, ​​​​​​​cours:2​​​​​}, ​​​​​2:{​​​​​​​id:2, ​​​​​​​year:2014, ​​​​​​​cours:2​​​​​}​​​}

–GET methodのREST APIを呼ぶ
on callRestGETAPIAndParseResults(aURL)
  –Request  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL)
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
  
–CALL REST API
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
  
–Parse Results
  
set resList to aRes as list
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code
  
set dRes to contents of second item of resList
  
set resCode to (dRes’s statusCode()) as list of string or string –as anything
  
  
–Get Response Header
  
set resHeaders to (dRes’s allHeaderFields()) as list of string or string –as anything
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
end callRestGETAPIAndParseResults

★Click Here to Open This Script 

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

POST method REST API__Slack_users.list

Posted on 2月 16, 2018 by Takaaki Naganoya

SlackのREST APIを呼び出してチーム内のユーザー一覧を取得する(users.list)AppleScriptです。

SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。

AppleScript名:POST method REST API__Slack_users.list.scptd
— Created 2016-03-23 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

set accessToken to retAccessToken() —Access Token
set reqURLStr to "https://slack.com/api/users.list"
set aRec to {token:accessToken, presence:"1"} –#applescript

set aRes to callRestPOSTAPIAndParseResults(reqURLStr, aRec) of me

set aRESTres to json of aRes
set aRESCode to responseCode of aRes

set aRESHeader to responseHeader of aRes
–>  {​​​​​Content-Type:"application/json; charset=utf-8", ​​​​​Access-Control-Allow-Origin:"*", ​​​​​X-Amz-Cf-Id:"zOmILG860ZDWHHwDA5h7HtLNDqYd8nlQyL-Wf_dKfC-b5jDKkr_p8A==", ​​​​​Content-Security-Policy:"referrer no-referrer;", ​​​​​Content-Encoding:"gzip", ​​​​​Server:"Apache", ​​​​​X-XSS-Protection:"0", ​​​​​Transfer-Encoding:"Identity", ​​​​​Via:"1.1 f8ebfacf2280f8de661be7a1f87ba74e.cloudfront.net (CloudFront)", ​​​​​Date:"Tue, 19 Apr 2016 06:16:37 GMT", ​​​​​Strict-Transport-Security:"max-age=31536000; includeSubDomains; preload", ​​​​​Connection:"keep-alive", ​​​​​X-Content-Type-Options:"nosniff", ​​​​​Vary:"Accept-Encoding", ​​​​​X-Cache:"Miss from cloudfront"​​​}

aRESTres as list of string or string
–>  {​​​​​members:{​​​​​​​{​​​​​​​​​id:"U11PVKT6D", ​​​​​​​​​real_name:"Takaaki Naganoya", ​​​​​​​​​profile:{​​​​​​​​​​​image_24:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0026-24.png", ​​​​​​​​​​​real_name:"Takaaki Naganoya", ​​​​​​​​​​​real_name_normalized:"Takaaki Naganoya", ​​​​​​​​​​​image_48:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F272a%2Fimg%2Favatars%2Fava_0026-48.png", ​​​​​​​​​​​image_72:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0026-72.png", ​​​​​​​​​​​image_192:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0026-192.png", ​​​​​​​​​​​avatar_hash:"ge7a98cc29b3", ​​​​​​​​​​​image_32:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F0180%2Fimg%2Favatars%2Fava_0026-32.png", ​​​​​​​​​​​first_name:"Takaaki", ​​​​​​​​​​​last_name:"Naganoya", ​​​​​​​​​​​email:"maro@piyocast.com", ​​​​​​​​​​​image_512:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0026-512.png"​​​​​​​​​}, ​​​​​​​​​is_owner:1, ​​​​​​​​​is_restricted:0, ​​​​​​​​​is_primary_owner:1, ​​​​​​​​​tz_label:"Japan Standard Time", ​​​​​​​​​is_ultra_restricted:0, ​​​​​​​​​tz:"Asia/Tokyo", ​​​​​​​​​has_2fa:0, ​​​​​​​​​presence:"active", ​​​​​​​​​color:"9f69e7", ​​​​​​​​​deleted:0, ​​​​​​​​​tz_offset:32400, ​​​​​​​​​is_bot:0, ​​​​​​​​​team_id:"T11N8QR19", ​​​​​​​​​is_admin:1, ​​​​​​​​​name:"maro", ​​​​​​​​​status:missing value​​​​​​​}, ​​​​​​​{​​​​​​​​​id:"USLACKBOT", ​​​​​​​​​real_name:"slackbot", ​​​​​​​​​profile:{​​​​​​​​​​​image_24:"https://a.slack-edge.com/0180/img/slackbot_24.png", ​​​​​​​​​​​real_name:"slackbot", ​​​​​​​​​​​image_48:"https://a.slack-edge.com/2fac/plugins/slackbot/assets/service_48.png", ​​​​​​​​​​​image_72:"https://a.slack-edge.com/0180/img/slackbot_72.png", ​​​​​​​​​​​image_192:"https://a.slack-edge.com/66f9/img/slackbot_192.png", ​​​​​​​​​​​real_name_normalized:"slackbot", ​​​​​​​​​​​image_32:"https://a.slack-edge.com/2fac/plugins/slackbot/assets/service_32.png", ​​​​​​​​​​​avatar_hash:"sv1444671949", ​​​​​​​​​​​fields:missing value, ​​​​​​​​​​​first_name:"slackbot", ​​​​​​​​​​​last_name:"", ​​​​​​​​​​​image_512:"https://a.slack-edge.com/7fa9/img/slackbot_512.png", ​​​​​​​​​​​email:missing value​​​​​​​​​}, ​​​​​​​​​is_owner:0, ​​​​​​​​​is_restricted:0, ​​​​​​​​​is_primary_owner:0, ​​​​​​​​​tz_label:"Pacific Daylight Time", ​​​​​​​​​is_ultra_restricted:0, ​​​​​​​​​tz:missing value, ​​​​​​​​​color:"757575", ​​​​​​​​​deleted:0, ​​​​​​​​​tz_offset:-25200, ​​​​​​​​​is_bot:0, ​​​​​​​​​team_id:"T11N8QR19", ​​​​​​​​​is_admin:0, ​​​​​​​​​name:"slackbot", ​​​​​​​​​status:missing value​​​​​​​}​​​​​}, ​​​​​cache_ts:1461054217, ​​​​​ok:1​​​}

–POST methodのREST APIを呼ぶ
on callRestPOSTAPIAndParseResults(aURL, aRec)
  
  
load framework
  
  
set aRes to retURLwithParams(aURL, aRec) of me
  
if aRes = false then return false
  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aRes)
  
aRequest’s setHTTPMethod:"POST"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
  
–aRequest’s setValue:(token of aRec) forHTTPHeaderField:"token"
  
–aRequest’s setValue:(channel of aRec) forHTTPHeaderField:"channel"
  
–aRequest’s setValue:"application/json" forHTTPHeaderField:"Content-Type"
  
–aRequest’s setHTTPBody:dataJson
  
  
–CALL REST API
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
  
–Parse Results
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
log resStr
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code
  
set dRes to contents of second item of resList
  
set resCode to ASify from (dRes’s statusCode())
  
  
–Get Response Header
  
set resHeaders to ASify from (dRes’s allHeaderFields())
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
  
end callRestPOSTAPIAndParseResults

on retAccessToken()
  return "xxxx-XXXXXXXXXXX-XXXXXXXXXXX-XXXXXXXXXXX-XXxXxxXXXX"
end retAccessToken

on retURLwithParams(aBaseURL, aRec)
  
  
set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
set bLen to length of aValList
  
if aLen is not equal to bLen then return false
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

★Click Here to Open This Script 

Posted in Network REST API | Tagged 10.11savvy 10.12savvy 10.13savvy Slack | Leave a comment

POST method REST API__Slack_users.info

Posted on 2月 16, 2018 by Takaaki Naganoya

SlackのREST APIを呼び出してチーム内のユーザー情報を取得する(users.info)AppleScriptです。

SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。

AppleScript名:POST method REST API__Slack_users.info.scptd
— Created 2016-03-23 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

set accessToken to retAccessToken() —Access Token
set reqURLStr to "https://slack.com/api/users.info"
set aRec to {token:accessToken, user:"U11PVKT6D"}

set aRes to callRestPOSTAPIAndParseResults(reqURLStr, aRec) of me

set aRESTres to json of aRes
set aRESCode to responseCode of aRes

set aRESHeader to responseHeader of aRes
–>  {​​​​​Content-Type:"application/json; charset=utf-8", ​​​​​Access-Control-Allow-Origin:"*", ​​​​​X-Amz-Cf-Id:"zOmILG860ZDWHHwDA5h7HtLNDqYd8nlQyL-Wf_dKfC-b5jDKkr_p8A==", ​​​​​Content-Security-Policy:"referrer no-referrer;", ​​​​​Content-Encoding:"gzip", ​​​​​Server:"Apache", ​​​​​X-XSS-Protection:"0", ​​​​​Transfer-Encoding:"Identity", ​​​​​Via:"1.1 f8ebfacf2280f8de661be7a1f87ba74e.cloudfront.net (CloudFront)", ​​​​​Date:"Tue, 19 Apr 2016 06:16:37 GMT", ​​​​​Strict-Transport-Security:"max-age=31536000; includeSubDomains; preload", ​​​​​Connection:"keep-alive", ​​​​​X-Content-Type-Options:"nosniff", ​​​​​Vary:"Accept-Encoding", ​​​​​X-Cache:"Miss from cloudfront"​​​}

aRESTres as list of string or string
–>   {​​​​​user:{​​​​​​​id:"U11PVKT6D", ​​​​​​​real_name:"Takaaki Naganoya", ​​​​​​​profile:{​​​​​​​​​image_24:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0026-24.png", ​​​​​​​​​real_name:"Takaaki Naganoya", ​​​​​​​​​real_name_normalized:"Takaaki Naganoya", ​​​​​​​​​image_48:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F272a%2Fimg%2Favatars%2Fava_0026-48.png", ​​​​​​​​​image_72:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0026-72.png", ​​​​​​​​​image_192:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0026-192.png", ​​​​​​​​​avatar_hash:"ge7a98cc29b3", ​​​​​​​​​image_32:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F0180%2Fimg%2Favatars%2Fava_0026-32.png", ​​​​​​​​​first_name:"Takaaki", ​​​​​​​​​last_name:"Naganoya", ​​​​​​​​​email:"maro@piyocast.com", ​​​​​​​​​image_512:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0026-512.png"​​​​​​​}, ​​​​​​​is_owner:1, ​​​​​​​is_restricted:0, ​​​​​​​is_primary_owner:1, ​​​​​​​tz_label:"Japan Standard Time", ​​​​​​​is_ultra_restricted:0, ​​​​​​​tz:"Asia/Tokyo", ​​​​​​​has_2fa:0, ​​​​​​​color:"9f69e7", ​​​​​​​deleted:0, ​​​​​​​tz_offset:32400, ​​​​​​​is_bot:0, ​​​​​​​team_id:"T11N8QR19", ​​​​​​​is_admin:1, ​​​​​​​name:"maro", ​​​​​​​status:missing value​​​​​}, ​​​​​ok:1​​​}

–POST methodのREST APIを呼ぶ
on callRestPOSTAPIAndParseResults(aURL, aRec)
  
  
load framework
  
  
set aRes to retURLwithParams(aURL, aRec) of me
  
if aRes = false then return false
  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aRes)
  
aRequest’s setHTTPMethod:"POST"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
  
–aRequest’s setValue:(token of aRec) forHTTPHeaderField:"token"
  
–aRequest’s setValue:(channel of aRec) forHTTPHeaderField:"channel"
  
–aRequest’s setValue:"application/json" forHTTPHeaderField:"Content-Type"
  
–aRequest’s setHTTPBody:dataJson
  
  
–CALL REST API
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
  
–Parse Results
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
log resStr
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code
  
set dRes to contents of second item of resList
  
set resCode to ASify from (dRes’s statusCode())
  
  
–Get Response Header
  
set resHeaders to ASify from (dRes’s allHeaderFields())
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
  
end callRestPOSTAPIAndParseResults

on retAccessToken()
  return "xxxx-XXXXXXXXXXX-XXXXXXXXXXX-XXXXXXXXXXX-XXxXxxXXXX"
end retAccessToken

on retURLwithParams(aBaseURL, aRec)
  
  
set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
set bLen to length of aValList
  
if aLen is not equal to bLen then return false
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

★Click Here to Open This Script 

Posted in Network REST API | Tagged 10.11savvy 10.12savvy 10.13savvy Slack | Leave a comment

POST method REST API__Slack_users.getPresence

Posted on 2月 16, 2018 by Takaaki Naganoya

SlackのREST APIを呼び出してユーザーの所在情報を取得する(users.getPresence)AppleScriptです。

SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。

AppleScript名:POST method REST API__Slack_users.getPresence.scptd
— Created 2016-03-23 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

set accessToken to retAccessToken() —Access Token
set reqURLStr to "https://slack.com/api/users.getPresence"
set aRec to {token:accessToken, user:"U11PVKT6D"}

set aRes to callRestPOSTAPIAndParseResults(reqURLStr, aRec) of me

set aRESTres to json of aRes
set aRESCode to responseCode of aRes

set aRESHeader to responseHeader of aRes
–>  {​​​​​Content-Type:"application/json; charset=utf-8", ​​​​​Access-Control-Allow-Origin:"*", ​​​​​X-Amz-Cf-Id:"zOmILG860ZDWHHwDA5h7HtLNDqYd8nlQyL-Wf_dKfC-b5jDKkr_p8A==", ​​​​​Content-Security-Policy:"referrer no-referrer;", ​​​​​Content-Encoding:"gzip", ​​​​​Server:"Apache", ​​​​​X-XSS-Protection:"0", ​​​​​Transfer-Encoding:"Identity", ​​​​​Via:"1.1 f8ebfacf2280f8de661be7a1f87ba74e.cloudfront.net (CloudFront)", ​​​​​Date:"Tue, 19 Apr 2016 06:16:37 GMT", ​​​​​Strict-Transport-Security:"max-age=31536000; includeSubDomains; preload", ​​​​​Connection:"keep-alive", ​​​​​X-Content-Type-Options:"nosniff", ​​​​​Vary:"Accept-Encoding", ​​​​​X-Cache:"Miss from cloudfront"​​​}

aRESTres as list of string or string
–>  {​​​​​presence:"away", ​​​​​auto_away:false, ​​​​​connection_count:0, ​​​​​online:false, ​​​​​ok:true, ​​​​​manual_away:false​​​}

–POST methodのREST APIを呼ぶ
on callRestPOSTAPIAndParseResults(aURL, aRec)
  
  
load framework
  
  
set aRes to retURLwithParams(aURL, aRec) of me
  
if aRes = false then return false
  
  
set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aRes)
  
aRequest’s setHTTPMethod:"POST"
  
aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData)
  
aRequest’s setHTTPShouldHandleCookies:false
  
aRequest’s setTimeoutInterval:60
  
  
–aRequest’s setValue:(token of aRec) forHTTPHeaderField:"token"
  
–aRequest’s setValue:(channel of aRec) forHTTPHeaderField:"channel"
  
–aRequest’s setValue:"application/json" forHTTPHeaderField:"Content-Type"
  
–aRequest’s setHTTPBody:dataJson
  
  
–CALL REST API
  
set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value)
  
  
–Parse Results
  
set resList to aRes as list
  
  
set bRes to contents of (first item of resList)
  
set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding)
  
log resStr
  
  
set jsonString to current application’s NSString’s stringWithString:resStr
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
–Get Response Code
  
set dRes to contents of second item of resList
  
set resCode to ASify from (dRes’s statusCode())
  
  
–Get Response Header
  
set resHeaders to ASify from (dRes’s allHeaderFields())
  
  
return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders}
  
end callRestPOSTAPIAndParseResults

on retAccessToken()
  return "xxxx-XXXXXXXXXXX-XXXXXXXXXXX-XXXXXXXXXXX-XXxXxxXXXX"
end retAccessToken

on retURLwithParams(aBaseURL, aRec)
  
  
set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
set bLen to length of aValList
  
if aLen is not equal to bLen then return false
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to contents of item i of aKeyList
    
set aVal to contents of item i of aValList
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

★Click Here to Open This Script 

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

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • Xcode 14.2でAppleScript App Templateを復活させる
  • macOS 13 TTS Voice環境に変更
  • UI Browserがgithub上でソース公開され、オープンソースに
  • 2022年に書いた価値あるAppleScript
  • ChatGPTで文章のベクトル化(Embedding)
  • iWork 12.2がリリースされた
  • ChatGPTでchatに対する応答文を取得
  • macOS 13対応アップデート:AppleScript実践的テクニック集(1)GUI Scripting
  • 新発売:CotEditor Scripting Book with AppleScript
  • macOS 14, Sonoma
  • macOS 13でNSNotFoundバグふたたび
  • Finderの隠し命令openVirtualLocationが発見される
  • あのコン過去ログビューワー(暫定版)
  • macOS 13.1アップデートでスクリプトエディタの挙動がようやくまともに
  • Dockアイコンにプログレスバーを追加 v3
  • クリップボードに入った書式つきテキストをプレーン化する「PlainerText」
  • CotEditor v4.4.1+macOS 13の組み合わせで発生している問題
  • 新発売:Mail.app Scripting Book with AppleScript

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (278) 12.0savvy (190) 13.0savvy (69) CotEditor (61) Finder (48) iTunes (19) Keynote (99) 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 (57) Pages (38) Safari (41) Script Editor (21) 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年11月
  • 2023年10月
  • 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