AppleScript名:URLにリソースが存在するかチェック v4 |
— Created 2016-10-18 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to "http://piyocast.com/as/wp-content/uploads/2018/02/map2-1024×796.png" set aURL to (current application’s |NSURL|’s URLWithString:aStr) set {exRes, headerRes, aData} to checkURLResourceExistence(aURL, 3) of me log exRes –> true / false return {exRes, headerRes as record} –> {true, {|content-type|:"image/png", |keep-alive|:"timeout=1, max=100", Server:"Apache", Expires:"Tue, 06 Feb 2018 09:52:20 GMT", |cache-control|:"max-age=300", |date|:"Tue, 06 Feb 2018 09:47:30 GMT", |content-length|:"323366", Connection:"Keep-Alive", |x-content-type-options|:"nosniff", Etag:"\"1f81fd7-4ef26-564871949b4c7\"", |accept-ranges|:"bytes", |last-modified|:"Tue, 06 Feb 2018 08:38:11 GMT"}} — 指定URLにファイル(画像など)が存在するかチェック –> {存在確認結果(boolean), レスポンスヘッダー(NSDictionary), データ(NSData)} 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 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} end checkURLResourceExistence |
(Visited 85 times, 1 visits today)
URLにリソースが存在するかチェック v5(NSURLSession) – AppleScriptの穴 says:
[…] 以前はNSURLConnectionを使って確認するものを使っていましたが、NSURLSessionへと移行しようかというところ。 […]