指定のURLを読み込んでページのタイトルを取得するAppleScriptです。
オリジナルはControl+Command+Rの操作が必要でしたが、本バージョンでは必要ありません。ただ、Script Debuggerとの相性はよろしくないようで。
AppleScript名:指定URLをロード_WKWebView版 v2 |
— Created 2015-09-16 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "WebKit" property theWebView : missing value set aURL to "http://www.apple.com/jp/shop/browse/home/specialdeals/mac" my performSelectorOnMainThread:"getPage:" withObject:(aURL) waitUntilDone:true set aTitle to (theWebView)’s title() return aTitle as text –> "Mac整備済製品 – Apple(日本)" –Download the URL page to WkWebView on getPage:aURL set thisURL to current application’s |NSURL|’s URLWithString:aURL set theRequest to current application’s NSURLRequest’s requestWithURL:thisURL set aConf to current application’s WKWebViewConfiguration’s alloc()’s init() set (my theWebView) to current application’s WKWebView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 800, 600)) configuration:aConf –フレームの大きさは根拠レス (my theWebView)’s setNavigationDelegate:me (my theWebView)’s loadRequest:theRequest set waitLoop to 100 * 60 –60 seconds set hitF to false repeat waitLoop times set aLoadF to ((my theWebView)’s estimatedProgress()) as number if aLoadF = 1.0 then set hitF to true exit repeat end if current application’s NSThread’s sleepForTimeInterval:(0.01) –delay 0.1 end repeat return hitF end getPage: |
More from my site
(Visited 55 times, 1 visits today)