Skip to content

Instantly share code, notes, and snippets.

@zarigani
Created June 10, 2009 07:32
Show Gist options
  • Select an option

  • Save zarigani/127072 to your computer and use it in GitHub Desktop.

Select an option

Save zarigani/127072 to your computer and use it in GitHub Desktop.

Revisions

  1. zarigani revised this gist Jun 12, 2009. 4 changed files with 188 additions and 3 deletions.
    90 changes: 90 additions & 0 deletions Opera_to_Other.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,90 @@
    (*
    このスクリプトは、現在Operaで開いている全ページを、指定したブラウザで一気に開きます。
    利用したいwebブラウザをアクティブにして、Opera_to_Other.scptを実行します。
    全てのページを一つの新規ウィンドウを開いて表示します。
    最前面のOperaウィンドウのみに限定することができます。(デフォルト)
    このスクリプトを動かすために必要なもの
    AppleScriptライブラリ
    依存するAppleScriptライブラリを以下のページからダウンロードしておく必要があります。
    https://github.com/zarigani/AppleScript-bebe-s-Library/tree/master
    そして、以下のファイルをユーザースクリプトフォルダ(~/Library/Scripts)にインストールしてください。
    _lib.scpt
    _gui.scpt
    *)
    property GUI : load script file ((path to scripts folder as text) & "_gui.scpt")
    property LIB : load script file ((path to scripts folder as text) & "_lib.scpt")

    --実行時に最前面のアプリケーションを保存する
    set app_name to GUI's frontmost_process()

    --Operaで開いているページのリストを取得する
    tell application "Opera"
    activate
    delay 0.5
    set tab_names to "" & LIB's join(my top_window_names(), return & "")
    "Operaで表示中のページを、" & app_name & "で開きます。" & return & return & tab_names
    display alert result buttons {"キャンセル", "全ウィンドウの全タブを開く", "このウィンドウの全タブを開く"} cancel button 1 default button 3 giving up after 30
    if result's button returned = "このウィンドウの全タブを開く" then
    set window_tab_urls to {my top_window_URLs()}
    else if result's button returned = "全ウィンドウの全タブを開く" then
    set window_tab_urls to my all_window_urls()
    else
    error number -128
    end if
    end tell

    --空のリストとTop Siteを除外する
    repeat with tab_urls in window_tab_urls
    if tab_urls's number > 0 then
    set tab_urls's contents to LIB's reject_if(tab_urls, "topsites://")
    end if
    end repeat
    --さらに、Top Siteを除外した結果、空になったリストを除外する
    set window_tab_urls to LIB's reject_if(window_tab_urls, {})

    --シングルクォートしたスペース区切りのURLテキストを生成する
    set url_options to "'" & LIB's join(window_tab_urls, "' '") & "'"
    --中身が存在すれば新規ウィンドウを開いて表示する
    if url_options "''" then
    tell application app_name to activate
    delay 0.5
    GUI's shortcut("", "command-N")
    delay 0.5
    do shell script ("open -a " & app_name & space & url_options)
    end if



    on all_window_urls()
    set url_list to {}
    tell application "System Events"
    tell process "Opera"
    repeat with a_windw in every window
    GUI's app_shortcut("Opera", "command-`")
    set url_list's end to my top_window_URLs()
    end repeat
    end tell
    end tell
    set url_list to LIB's reject_if(url_list, {{}})
    end all_window_urls

    on top_window_URLs()
    each_document("URL")
    end top_window_URLs

    on top_window_names()
    each_document("name")
    end top_window_names

    on each_document(option)
    tell application "Opera"
    set doc_num to count window 1's documents
    set a_list to {}
    repeat with i from 1 to doc_num
    set a_list's end to run script ("document " & i & "'s " & option)
    end repeat
    end tell
    a_list's reverse
    end each_document
    9 changes: 6 additions & 3 deletions Safari_to_Other.scpt
    Original file line number Diff line number Diff line change
    @@ -22,9 +22,10 @@ set app_name to GUI's frontmost_process()
    --Safariで開いているページのリストを取得する
    tell application "Safari"
    activate
    delay 0.5
    set top_win to window 1
    set tab_names to top_win's tab's name
    set tab_names to "" & LIB's join(tab_names, "\n")
    set tab_names to "" & LIB's join(tab_names, return & "")
    "Safariで表示中のページを、" & app_name & "で開きます。" & return & return & tab_names
    display alert result buttons {"キャンセル", "全ウィンドウの全タブを開く", "最前面の上記タブのみ開く"} cancel button 1 default button 3 giving up after 30
    if result's button returned = "最前面の上記タブのみ開く" then
    @@ -49,7 +50,9 @@ set window_tab_urls to LIB's reject_if(window_tab_urls, {})
    set url_options to "'" & LIB's join(window_tab_urls, "' '") & "'"
    --中身が存在すれば新規ウィンドウを開いて表示する
    if url_options "''" then
    GUI's shortcut(app_name, "command-N")
    delay 1
    tell application app_name to activate
    delay 0.5
    GUI's shortcut("", "command-N")
    delay 0.5
    do shell script ("open -a " & app_name & space & url_options)
    end if
    65 changes: 65 additions & 0 deletions get_URLs.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    (*
    このスクリプトは、アクティブなブラウザで表示中の全URLを取得します。
    取得したいwebブラウザをアクティブにして、get_URLs.scptを実行します。
    取得したURLは、open_URLs.scptにて一気に開くことが出来ます。
    このスクリプトを動かすために必要なもの
    AppleScriptライブラリ
    依存するAppleScriptライブラリを以下のページからダウンロードしておく必要があります。
    https://github.com/zarigani/AppleScript-bebe-s-Library/tree/master
    そして、以下のファイルをユーザースクリプトフォルダ(~/Library/Scripts)にインストールしてください。
    _lib.scpt
    _gui.scpt
    *)
    property GUI : load script file ((path to scripts folder as text) & "_gui.scpt")
    property LIB : load script file ((path to scripts folder as text) & "_lib.scpt")

    property NEXT_TABS : {{"Safari", "control-tab"}, {"Shiira", "command-shift-}"}, {"Firefox", "command-option-→"}, {"Opera", "command-option-→"}}

    GUI's init_with_interval(0.18)
    set app_name to GUI's frontmost_app()
    set next_tab to LIB's look_up_with_default(NEXT_TABS, app_name, "command-option-→")

    activate
    app_name & "で表示中のURLを取得します。" -- & return & return & tab_names
    display alert result buttons {"キャンセル", "全ウィンドウの全URL", "このウィンドウの全URL"} cancel button 1 default button 3 giving up after 30
    if result's button returned = "このウィンドウの全URL" then
    set url_list to top_window_URLs(app_name, next_tab)
    else if result's button returned = "全ウィンドウの全URL" then
    set url_list to all_window_urls(app_name, next_tab)
    else
    error number -128
    end if

    set the clipboard to "'" & LIB's join(url_list, "' '") & "'"
    set url_num to (count LIB's split(the clipboard as text, "' '")) as text
    LIB's message(app_name, url_num & " URLを取得できました。" & return & LIB's join(url_list, return))



    on all_window_urls(app_name, next_tab)
    set url_list to {}
    tell application "System Events"
    tell process app_name
    repeat with a_windw in every window
    GUI's app_shortcut(app_name, "command-`")
    set url_list's end to my top_window_URLs(app_name, next_tab)
    end repeat
    end tell
    end tell
    set url_list to LIB's reject_if(url_list, {{}})
    end all_window_urls

    on top_window_URLs(app_name, next_tab)
    set url_list to {}
    repeat
    set the clipboard to ""
    GUI's shortcut(app_name, "command-L")
    GUI's shortcut(app_name, "command-C")
    if (the clipboard as text) is in url_list then exit repeat
    set url_list's end to the clipboard as text
    GUI's shortcut(app_name, next_tab)
    end repeat
    set url_list to LIB's reject_if(url_list, {""})
    end top_window_URLs
    27 changes: 27 additions & 0 deletions open_URLs.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    (*
    このスクリプトは、get_URLs.scptで取得したURLを使って、指定したブラウザで開きます。
    利用したいwebブラウザをアクティブにして、このスクリプトを実行します。
    ブラウザの設定によっては、タブでなく、ウィンドウが複数開いてしまう可能性もあります。
    このスクリプトを動かすために必要なもの
    AppleScriptライブラリ
    依存するAppleScriptライブラリを以下のページからダウンロードしておく必要があります。
    https://github.com/zarigani/AppleScript-bebe-s-Library/tree/master
    そして、以下のファイルをユーザースクリプトフォルダ(~/Library/Scripts)にインストールしてください。
    _lib.scpt
    _gui.scpt
    *)
    property GUI : load script file ((path to scripts folder as text) & "_gui.scpt")
    property LIB : load script file ((path to scripts folder as text) & "_lib.scpt")

    GUI's init()
    --実行時に最前面のアプリケーションを保存する
    set app_name to GUI's frontmost_process()

    set url_options to the clipboard as text
    if url_options "''" then
    GUI's shortcut(app_name, "command-N")
    delay 1
    do shell script ("open -a " & app_name & space & url_options)
    end if
  2. zarigani revised this gist Jun 10, 2009. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Safari_to_Other.scpt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    (*
    Safari_to_Other.scpt
    このスクリプトは、現在Safariで開いている全ページを、指定したブラウザで一気に開きます。
    利用したいwebブラウザをアクティブにして、Safari_to_Other.scptを実行します。
    全てのページを一つの新規ウィンドウを開いて表示します。
  3. zarigani created this gist Jun 10, 2009.
    56 changes: 56 additions & 0 deletions Safari_to_Other.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    (*
    Safari_to_Other.scpt
    このスクリプトは、現在Safariで開いている全ページを、指定したブラウザで一気に開きます。
    利用したいwebブラウザをアクティブにして、Safari_to_Other.scptを実行します。
    全てのページを一つの新規ウィンドウを開いて表示します。
    最前面のSafariウィンドウのみに限定することができます。(デフォルト)
    このスクリプトを動かすために必要なもの
    AppleScriptライブラリ
    依存するAppleScriptライブラリを以下のページからダウンロードしておく必要があります。
    https://github.com/zarigani/AppleScript-bebe-s-Library/tree/master
    そして、以下のファイルをユーザースクリプトフォルダ(~/Library/Scripts)にインストールしてください。
    _lib.scpt
    _gui.scpt
    *)
    property GUI : load script file ((path to scripts folder as text) & "_gui.scpt")
    property LIB : load script file ((path to scripts folder as text) & "_lib.scpt")

    --実行時に最前面のアプリケーションを保存する
    set app_name to GUI's frontmost_process()

    --Safariで開いているページのリストを取得する
    tell application "Safari"
    activate
    set top_win to window 1
    set tab_names to top_win's tab's name
    set tab_names to "" & LIB's join(tab_names, "\n")
    "Safariで表示中のページを、" & app_name & "で開きます。" & return & return & tab_names
    display alert result buttons {"キャンセル", "全ウィンドウの全タブを開く", "最前面の上記タブのみ開く"} cancel button 1 default button 3 giving up after 30
    if result's button returned = "最前面の上記タブのみ開く" then
    set window_tab_urls to {top_win's tab's URL}
    else if result's button returned = "全ウィンドウの全タブを開く" then
    set window_tab_urls to windows's tab's URL
    else
    error number -128
    end if
    end tell

    --空のリストとTop Siteを除外する
    repeat with tab_urls in window_tab_urls
    if tab_urls's number > 0 then
    set tab_urls's contents to LIB's reject_if(tab_urls, "topsites://")
    end if
    end repeat
    --さらに、Top Siteを除外した結果、空になったリストを除外する
    set window_tab_urls to LIB's reject_if(window_tab_urls, {})

    --シングルクォートしたスペース区切りのURLテキストを生成する
    set url_options to "'" & LIB's join(window_tab_urls, "' '") & "'"
    --中身が存在すれば新規ウィンドウを開いて表示する
    if url_options "''" then
    GUI's shortcut(app_name, "command-N")
    delay 1
    do shell script ("open -a " & app_name & space & url_options)
    end if