オープン中のSafariタブを列挙し、見つけ出し、移動するAppleScript(List all pages of Safari,find a page,and invoke it)

よく巡るサイトやブログのネタとなるページを開きっぱなしにしている。夥しすぎて特定のページを発見できない。

 

そこで全てのページを列挙するアプリをAppleScriptで作った。

 

Safariのwindowを列挙し、

各windowのタブを列挙し、

各タブのタイトルとURLでHTMLの<a>タグを構成する。

 

それをNotes.appのnoteとして作成する。

 

noteなので検索できる。

“here”をクリックすると当該ページヘ遷移する。

 

Notesはリンクの色が変えられない。タイトルにリンクを張ると読みにくくなる。そこでhereを導入した。

“here”を押すとページがリロードされる。朝日新聞や立件民主盗の類はページを消す。リロードすると折角の情報がなくなってしまう。🍓は各ページに一つつく。目的のページの”here”ではなく、🍓の”here”を押しタブを見つけて移動すればリロードを避けられる場合がある。

 

 

tell application "Safari"

  set windowCount to number of windows

  set docText to "Show all web pages<br><html><body>"

  repeat with x from 1 to windowCount

    set tabcount to number of tabs in window x

    set docText to docText & "🍓"

    repeat with y from 1 to tabcount

       set tabName to name of tab y of window x

       set theURL to URL of tab y of window x

       set docText to docText & "⭐️ " & tabName & "<a href=\"" & theURL & "\"> here </a><br>"

    end repeat

  end repeat

 

 tell application "Notes"

   activate

    tell account "On My Mac"

       tell folder "Notes"

         try

           set body of note "Show all web pages" to docText

       on error

          make new note with properties {name:"Show all web pages", body:docText}

          set body of note "Show all web pages" to docText

       end try

     end tell

   end tell

 end tell

end tell

 

I open too many Safari pages.I cannot find a specific page.

So,I build a AppleScript app.

 

Enumerate Window of Safari,

Enumerate tabs of each Window,

Build a HTML <a> tag using Title and URL of each tab.

Paste <a> tags to Notes.app.

The new note is created in Notes folder of On My Mac.

 

press “here”,the page is invoked.

 

The invoked page is reloaded. Sometime, reload loss the original page. To avoid this, Press “here” of 🍓, then find a target tab.