Safariのタブページの保存について

Safariで閲覧中の複数のタブで開いているページを保存して後で復元したいと思っています。ちょうどOpera Browserのセッションの保存のような感じです。
しかし、Safariの用語説明を開いてもタブに相当するようなObjectが見当たらないように思います。まだ、タブの要素がAppleScriptに対応していないのでしょうか。
それならそれで、タブをひとつづつURLを取得しては閉じてと繰り返すやり方もありかと思うのですが、AppleScriptを通じてcmd+wのようなキーバインドを送る方法はあるのでしょうか。
よろしかったらご教授ください。

投稿日 2006/10/24 16:09

返信: 7

2006/10/24 19:54 Community User への返信

> AppleScriptを通じてcmd+wのようなキーバインドを送る方法はあるのでしょうか
System Eventsのkeystrokeコマンドで可能です。ショートカットがない操作でも、メニューバーに直接アクセすることも可能です。(ちゃんとスクリプティングするには、ちょっと慣れが必要ですが。)System Eventsの用語説明を詳細を調べるのも良いのですが、ネットでググって見ると、似たようなスクリプトが見つかると思います。
タブの終わりは、「次のタブへ移動してもURLが変化しない」ことで判定すれば良いようです。
スクリプティングに成功したら、ぜひ紹介してくださいね。

2006/10/25 03:19 Community User への返信

ためになるご意見ありがとうございます。これを足がかりにさっそく精進しよーとググリはじめたら見つけちゃいましたよ、そのものズバリのソースを、、、
http://www.geocities.jp/aqua7bowler/applescript/safari_to_weblocs.html
何となく後ろめたさをおぼえつつも、とりあえず目的を果たしてしまった満足感を感じています。今後はこのソースを自力で解読するところから始めたいと思います。(苦笑

2006/10/25 05:27 Community User への返信

なるほど。タブを3番目のバーにあるボタンとして扱ってますな。こういう方法も取れるんですね。
蛇足ですが、「参考」にある「MacScripter BBS」はスクリプトの宝庫ですから、まだ行かれたことがないなら是非覗いてみられるといいです。英語が出来るなら、質問すれば(要登録)このボード並に素早い回答が来ます。

2006/10/25 06:59 Community User への返信

> タブを3番目のバーにあるボタンとして扱ってますな。
ざっと眺めた感じ、ここが一番目から鱗な部分ですよね。
> 「MacScripter BBS」はスクリプトの宝庫です
そうですね。Mac関係はWindowsと比べると相対的に情報も少なくなってきますから、英語だからといって敬遠せずに積極的に情報収集すべきなのでしょうね。読むだけなら何とかなりそうなので、がんばってみたいと思います。

2006/11/07 18:40 Community User への返信

同じこと考えるヒトがいるもんですね(^_^)
最近やっとまともに動作するようになったんですけど、いちおー複数ウィンドウとウィンドウサイズ復帰に対応してます。
ただし保存したら、全ウィンドウが閉じてしまうのは仕様なので、気に入らなかったら書き換えて下さい(T_T)
私はスクリプトメニュー有効にして、Safariスクリプトフォルダに入れて使用してます。
ちょっと長いけど2つに分けてコピペ。
注意点は2点。
1)URLを再読み込みするのでタブの復帰途中に、読み込みに時間のかかるかなり重たいページや、
サーバからのレスポンスが悪いページが間にあると、Receiveエラーで処理が中断してタブの復帰が停止します(T_T)
が、再度復帰実行すれば、キャッシュが使用されるので大体うまく復帰できます。
(このへんはWaitブロック入れるなりしたら止まることは無くなるかもしれませんけど)
2)IntelMacのヒトは"UI elements enabled"が動作しないみたい
(get propertiesがUI elements enabled:trueじゃなくてmissing valueになる)
だから"if UI elements enabled then"→"if true then"に置換して下さいな♪
=-=-=-=-=-=-==-
property tList : ""
property urls : {}
property wbounds : {}
global bb
on run
tell application "System Events"
get properties
if UI elements enabled then
tell application "Safari"
if (count every document) is 0 then
set ssss to "過去のウィンドウ情報に復帰しますか?"
set sss to "復帰"
else
set ssss to "全てのウィンドウ情報を保存しますか?"
set sss to "保存"
end if
end tell
display dialog ssss buttons {"保存", "復帰", "キャンセル"} default button sss
set theResults to result
if button returned of theResults is "保存" then
my save_tab()
end if
if button returned of theResults is "復帰" then
--choose from list tList
my resume_tab()
end if
else
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "「UI element scripting」" & return & "が使用できません。" & return & "「補助装置を使用可能にする」を" & return & "チェックして「入」にしてから" & return & "このスクリプトを実行して下さい。" with icon 0
end tell
end if
end tell
end run

2006/11/07 18:45 Community User への返信

on resume_tab()
tell application "Safari"
try
repeat with xxx from (count items of urls) to 1 by -1
set bb to false
repeat with yyy from 1 to (count item of item xxx of urls)
if yyy is 1 then
make new document with properties {URL:(item yyy of item xxx of urls)}
else
my new_tab()
set the URL of document 1 to (item yyy of item xxx of urls)
set bb to true
end if
end repeat
set bounds of window 1 to (item xxx of wbounds)
if bb then
my next_tab()
end if
end repeat
on error the error_message number the error_number
display dialog the error_message buttons {"OK"} default button 1
end try
end tell
end resume_tab
on save_tab()
tell application "Safari"
try
set ss to ""
set urls to {}
set wbounds to {}
if (name of window 1) is "ダウンロード" then
my close_window()
end if
my close_prefs()
my close_find()
repeat with i from 1 to (count every document)
my new_tab()
my close_tab()
my next_tab()
if (name of window 1) is "ダウンロード" then
my close_window()
set i to i + 1
end if
set xurls to {}
repeat 50 times
set ss to (name of document 1)
if (ss does not contain "名称未設定") then
set ss to (URL of document 1)
if (ss is not in xurls) then
set xurls to xurls & ss
else
exit repeat
end if
end if
set bb to false
my next_tab()
if bb then
exit repeat
end if
end repeat
if urls is {} then
set urls to {xurls}
else
set urls to urls & {xurls}
end if

if wbounds is {} then
set wbounds to {bounds of window 1}
else
set wbounds to wbounds & {bounds of window 1}
end if
my close_window()

if (count every document) is 0 then
exit repeat
end if
end repeat
on error the error_message number the error_number
display dialog the error_message buttons {"OK"} default button 1
end try
end tell
end save_tab
on next_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
if enabled of menu item "次のタブを選択" of menu "ウインドウ" of menu bar 1 then
click menu item "次のタブを選択" of menu "ウインドウ" of menu bar 1
else
set bb to true
end if
end tell
end tell
end next_tab
on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "新規タブ" of menu "ファイル" of menu bar 1
end tell
end tell
end new_tab
on close_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
if enabled of menu item "タブを閉じる" of menu "ファイル" of menu bar 1 then
click menu item "タブを閉じる" of menu "ファイル" of menu bar 1
else
set bb to true
end if
end tell
end tell
end close_tab
on close_window()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "ウインドウを閉じる" of menu "ファイル" of menu bar 1
end tell
end tell
end close_window
on close_prefs()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "環境設定..." of menu "Safari" of menu bar 1
end tell
end tell
my close_window()
end close_prefs
on close_find()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "検索..." of menu "検索" of menu item "検索" of menu "編集" of menu bar 1
end tell
end tell
my close_window()
end close_find
=-=-=-=-=-=-==-
別れてるけど1ファイルですからねー(@_@)♭
"repeat 50 times "を書き換えて最大タブ数の変更できますっ
(↑タブ枚数数えるスクリプトはメンドクサかったので…(T_T)

2006/11/09 05:53 Community User への返信

新しい情報ありがとうございます。
これも面白いスクリプトですね。SafariのDebugメニューが出てくるのが印象的です。
以前見つけたスクリプトとあわせて勉強させていただきたいと思います。

このスレッドはシステム、またはAppleコミュニティチームによってロックされました。 問題解決の参考になる情報であれば、どの投稿にでも投票いただけます。またコミュニティで他の回答を検索することもできます。

Safariのタブページの保存について

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