2009-03-19
■[Safari][AppleScript]Safariで開いているページの一時保存・リストア
あなたはいま、Safariでいくつかのウィンドウ(とタブ)を開いていて、いろいろ調べものをしているとする。
そんな時に限って上司が「おいキミ、ウェッブサーフィン(死語)やってるんなら、この仕事を片付けてくれないか」などと言うのだ。
せっかくいっぱいぐぐって、ページを開いたのに。。。
こんなとき、これを使うと便利。いま開いているページ状態を「Set」で記憶しておいてくれる。またウェッブサーフィン(死語)をやりたくなったら「Restore」すればいい。
- ちょっと違う仕事をしたいとき
- 睡魔に勝てなくなったとき
- 明日があるさ、と思ったとき
再開するまで、あなたのSafariの状態を記憶しておいてくれるってこと。
property my_windows : {}
property my_titles : {}
to list2paragraph(aList)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set aString to aList as text
set AppleScript's text item delimiters to oldDelims
return aString
end list2paragraph
tell application "Safari"
set ans to button returned of (display dialog "Set or Restore?" & return & "-------------------------------- now setting" & return & my list2paragraph(my_titles) buttons {"Cancel", "Set", "Restore"})
if ans is "Set" then
set my_windows to {}
set my_titles to {}
repeat with i from 1 to (count every document)
set end of my_windows to URL of every tab of window i
set end of my_titles to name of every tab of window i
end repeat
else --Restore
repeat with i from 1 to (length of my_windows)
repeat with ii from 1 to (length of item i of my_windows)
set my_url to item ii of item i of my_windows
if ii is 1 then
make new document with properties {URL:my_url}
else
tell window 1
set tmp_tab to make new tab --with properties {URL:my_url}--Safari5.1ではpropertiesを指定してもURLがロードされない。バグかな。
set URL of tmp_tab to my_url
end tell
end if
end repeat
end repeat
end if
end tell
コンパイルしたくない人はこれをダウンロード→:Restore_URL.app.zip ![]()
追記
(2009-03-19T14:00:00JST)タイトルを変更しました。
自画自賛なのだけど、とても便利^^ いままでどうしてたんだろうって思うくらい。URLは保存したアップレット自体が持っているので、違うページを同時にセットしたくなったら、アプリごとコピーすればいいだけ。アプリケーションバンドルでも96KBと軽量だし。
(追記:2011-10-08T00:20:27+0900)Safari 5.1でRestoreした時、tabにURLがロードされなくなったのを修正した。Safari 5.1のバグかな。
トラックバック - http://d.hatena.ne.jp/seuzo/20090319/1237406389
リンク元
- 86 http://www.google.co.jp/search?client=safari&rls=en&q=safari+タブ 保存&ie=UTF-8&oe=UTF-8&redir_esc=&ei=ArmPS73mNc2HkAW_k42LDQ
- 54 http://www.seuzo.jp/st/index.html
- 39 http://www.google.com/search?client=safari&rls=en&q=safari+タブ 保存&ie=UTF-8&oe=UTF-8
- 15 http://dtpwiki.jp/planet/
- 15 http://www.google.co.jp/search?client=safari&rls=en&q=Safari タブ 保存&ie=UTF-8&oe=UTF-8&redir_esc=&ei=J4fES9HqA9CTkAXwoeSODg
- 15 http://www.google.co.jp/search?hl=ja&q=safari+タブ 保存&btnG=検索&lr=
- 14 http://www.google.co.jp/search?hl=ja&source=hp&q=safari+タブ+保存&btnG=Google+検索&lr=&aq=1&oq=SAFARI タブ
- 13 http://www.google.com/search?client=safari&rls=ja-jp&q=Safari+リストアしたい&ie=UTF-8&oe=UTF-8
- 9 http://www.google.co.jp/search?client=safari&rls=en&q=safari+Restore+Window&ie=UTF-8&oe=UTF-8&redir_esc=&ei=PMsNTPSoJ9DJcbSuqb0O
- 9 http://www.google.co.jp/search?hl=ja&client=safari&rls=en&q=safari+一時保存&btnG=検索&lr=



