AppleScript名:指定URLをロードしてtitleを取得 |
— Created 2015-09-07 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "WebKit" property loadDone : false property theWebView : missing value set aURL to "https://www.youtube.com/watch?v=WuziqYptTyE" set aTitle to getPageTitle(aURL) –> "戦場の絆ポータブル【HD】鉱山都市 オンライン対戦 2015.09.04 – YouTube" on getPageTitle(aURL) –Check If this script runs in foreground if not (current application’s NSThread’s isMainThread()) as boolean then display alert "This script must be run from the main thread (Command-Control-R in Script Editor)." buttons {"Cancel"} as critical error number -128 end if set my loadDone to false set my theWebView to missing value openURL(aURL) set waitLoop to 1000 * 60 –60 seconds set hitF to false repeat waitLoop times if my loadDone = true then set hitF to true exit repeat end if current application’s NSThread’s sleepForTimeInterval:("0.001" as real) –delay 0.001 end repeat if hitF = false then return set jsText to "document.title" set x to ((my theWebView)’s stringByEvaluatingJavaScriptFromString:jsText) as text set my theWebView to missing value return x end getPageTitle –WebViewにURLを読み込む on openURL(aURL) set noter1 to current application’s NSNotificationCenter’s defaultCenter() set my theWebView to current application’s WebView’s alloc()’s init() noter1’s addObserver:me selector:"webLoaded:" |name|:(current application’s WebViewProgressFinishedNotification) object:(my theWebView) my (theWebView’s setMainFrameURL:aURL) end openURL –Web Viewのローディング完了時に実行 on webLoaded:aNotification set my loadDone to true end webLoaded: |
More from my site
(Visited 75 times, 1 visits today)