Apple の脅威の通知と金銭目当てのスパイウェアへの対策について

しばらく返答が寄せられていないようです。 再度ディスカッションを開始するには、新たに質問してください。

AppleScriptでSafariのwebarchiveを保存したい

サファリでURLにアクセスしてwebarchiveを保存するAppleScriptを作りました。

下記「delay 2」の部分を、きちんとURLが開くまで判断して待つようにできないでしょうか?

又、もう少しスマートな方法(UIのシステムイベントをなるべく使わない)で、webarchiveの保存ができないものでしょうか?


set the target_URL to "http://www.goo.ne.jp/"

set save_nam to "abc"

tellapplication "Safari" tomakenewdocumentwith properties {URL:target_URL}

tellapplication "Safari" toactivate

--

-- URLで判断したいが方法がわからない

delay 2

--

tell application "System Events"

tell process "Safari"


keystroke "s" usingcommand down -- Save As…


repeatuntilsheet 1 ofwindow 1 exists

delay 0.1


endrepeat


keystroke "d" usingcommand down -- save to Desktop


keystrokesave_nam -- set save file name


repeat

delay 0.1


ifnot (existssheet 1 ofwindow 1) thenexitrepeat


endrepeat


endtell

endtell

PowerMac G5-OTHER, Mac OS X (10.4.11)

投稿日 2013/01/27 00:16

返信
スレッドに付いたマーク ベストな回答

投稿日 2013/01/27 14:48

下記「delay 2」の部分を、きちんとURLが開くまで判断して待つようにできないでしょうか?


applescript: Safariでページロードを待つ処理

http://tezfm.blogspot.jp/2009/10/applescript.html


リンク先にある openWithWait() がそのまま使えると思います。当方 Tiger 環境がないので確認できませんが、Leopard では一応動きます。


もう少しスマートな方法


多分ないと思います。


-----


ということで、こんな感じでどうでしょうか?


on run

set target_URL to "http://www.goo.ne.jp/"

my openWithWait(target_URL, 10) -- タイムアウト: 10秒 (秒数は適当)

if result is true then

tell application "System Events"

tell process "Safari"

-- webarchive で保存する処理

end tell

end tell

end if

end run

--

on openWithWait(theUrl, timeoutSec)

-- 省略

end openWithWait

返信: 2
スレッドに付いたマーク ベストな回答

2013/01/27 14:48 el156 への返信

下記「delay 2」の部分を、きちんとURLが開くまで判断して待つようにできないでしょうか?


applescript: Safariでページロードを待つ処理

http://tezfm.blogspot.jp/2009/10/applescript.html


リンク先にある openWithWait() がそのまま使えると思います。当方 Tiger 環境がないので確認できませんが、Leopard では一応動きます。


もう少しスマートな方法


多分ないと思います。


-----


ということで、こんな感じでどうでしょうか?


on run

set target_URL to "http://www.goo.ne.jp/"

my openWithWait(target_URL, 10) -- タイムアウト: 10秒 (秒数は適当)

if result is true then

tell application "System Events"

tell process "Safari"

-- webarchive で保存する処理

end tell

end tell

end if

end run

--

on openWithWait(theUrl, timeoutSec)

-- 省略

end openWithWait

2013/01/27 20:07 Hiro__S への返信

Hiro.Sさん、有難うございました。

JavaScriptはさっぱりわかりませんが、リンク先のopenWithWait()のサブルーチンを展開して私のスクリプトにそのまま埋め込んだら、すんなり動きました。Tigerでも問題ありませんでした。たいへん助かりました。

AppleScriptでSafariのwebarchiveを保存したい

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple ID を使ってご参加ください。