AppleScript名:指定のアプリケーションのURL Schemeを取得する |
— Created 2017-07-23 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use BridgePlus : script "BridgePlus" –http://piyocast.com/as/archives/4759 load framework set aP to choose file set aURLrec to getAppURLSchemes(aP) of me –> {appName:"Photos", appBundleID:"com.apple.Photos", urlScheme:{"photos"}} on getAppURLSchemes(aP) set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aP) set aBundle to current application’s NSBundle’s bundleWithURL:aURL set aDict to aBundle’s infoDictionary() set appNameDat to (aDict’s valueForKey:"CFBundleName") as string set bundleIDat to (aDict’s valueForKey:"CFBundleIdentifier") as string set urlSchemes to (aDict’s valueForKey:"CFBundleURLTypes") if urlSchemes is not equal to missing value then set urlList to urlSchemes’s valueForKey:"CFBundleURLSchemes" set urlListFlat to (current application’s SMSForder’s arrayByFlattening:urlList) as list else set urlListFlat to {} end if set aRec to {appName:appNameDat, appBundleID:bundleIDat, urlScheme:urlListFlat} return aRec end getAppURLSchemes |
カテゴリー: URL
文字列のURLエンコード、URLデコード
AppleScript名:文字列のURLエンコード、URLデコード |
— Created 2017-09-19 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to "あいうえお" set bStr to encodeURLencoding(aStr) of me –> "%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A" set cStr to decodeURLencoding(bStr) of me –> "あいうえお" on encodeURLencoding(origStr as string) set aStr to current application’s NSString’s stringWithString:origStr set encodedStr to aStr’s stringByAddingPercentEscapesUsingEncoding:(current application’s NSUTF8StringEncoding) return encodedStr as string end encodeURLencoding on decodeURLencoding(encodedStr) set aStr to current application’s NSString’s stringWithString:encodedStr set bStr to aStr’s stringByReplacingPercentEscapesUsingEncoding:(current application’s NSUTF8StringEncoding) return bStr as string end decodeURLencoding |
Maps.appで開始地点と到着地点の住所を指定して経路表示 v3
AppleScript名:Maps.appで開始地点と到着地点の住所を指定して経路表示 v3 |
— Created 2017-01-17 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aURL to "http://maps.apple.com/" set aRec to {saddr:"中村橋駅", daddr:"よみうりホール"} –経路表示 set bURL to retURLwithParams(aURL as string, aRec as record) open location bURL on retURLwithParams(aBaseURL as string, aRec as record) 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) as string set aVal to (contents of item i of aValList) as string 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 |
com.apple.Maps
Maps.appで住所検索表示 v4
AppleScript名:Map.appで住所検索表示 v4 |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set aBaseURL to "http://maps.apple.com/" set aParam to "東京都港区六本木6丁目10番1号" –Apple Japanの住所 set aRec to {q:aParam} set cURL to retURLwithParams(aBaseURL, aRec) of me tell application "Maps" open location cURL end tell on retURLwithParams(aBaseURL as string, aRec as record) 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) as string set aVal to (contents of item i of aValList) as string 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 |
com.apple.Maps
SafariでURLをローディング
本処理は最近のSafariでは正しくローディング検出できないようになってきたため、書き直したルーチン「SafariでURLローディング完了検出」を利用してください。
AppleScript名:SafariでURLをローディング |
set aURL to "http://www.piyocast.com/as/" –set aURL to "" tell application "Safari" set d to count every window if d = 0 then make new window tell document 1 set URL to aURL end tell else if aURL is not equal to "" then tell document 1 set URL to aURL end tell end if end if page_loaded(10) of me set a to do JavaScript "document.title" in document 1 end tell on page_loaded(timeout_value) repeat with i from 1 to (timeout_value * 10) tell application "Safari" if (do JavaScript "document.readyState" in document 1) is "complete" then return true else if i is the timeout_value then return false else delay 0.1 end if end tell end repeat return false end page_loaded |