mozyのかきおき

mozyの読書感想文や思考置き場

数百とか開いているSafariのタブ情報をエクスポートする方法【実際にやってみた】

経緯

つまりはこういうことだ。
開きすぎる癖があって、これをどうにかしてCSVなりに書き出したかった。
あなたもこういう癖あったりしませんか?

f:id:mozy_ok:20190126131319j:plain
つまりはこういうことだ

iPhoneのストレージも逼迫するし。

探していたところ

かみさーまー みたいな記事を発見した。BOOOM!!!

Ok!!! This has been SOLVED. For those who were wondering...

The post request to https://p58-ckdatabase.icloud.com/api/client/record/sync contained gzip-encoded information which made reference to SafariBookmarksSyncAgent.

SafariBookmarksSyncAgent is located at /System/Library/CoreServices/SafariSupport.bundle/Contents/MacOS/SafariBookmarksSyncAgent.

Ran strings on the binary and saw it made reference to: (allow file* (home-literal "/Library/Safari/CloudTabs.db"))

/Library/Safari/CloudTabs.db does not exist, but ~/Library/Safari/CloudTabs.db does!

CloudTabs.db is a SQLite3 database with table cloud_tabs and cloud_tab_devices.

select * from cloud_tab_devices gives the device_uuid in column 1.

select url from cloud_tabs where device_uuid='';

BOOM!

Reddit - mac - iPhone Safari Tabs into Text List via iCloud?

実際にやってみた

  1. まずは、iPhone 設定 > iCloud から Safariの設定をOnにする

  2. ターミナルでSafariのブックマークの同期をするエージェントを動かす。
    /System/Library/CoreServices/SafariSupport.bundle/Contents/MacOS/SafariBookmarksSyncAgent

    f:id:mozy_ok:20190202162136p:plain
    手動で同期する

  3. SQLite なデータベース ~/Library/Safari/CloudTabs.dbを見つけて開く 

    f:id:mozy_ok:20190202162234p:plain
    このDBの中にタブ情報が入っている

  4. データベースの中身はこんな感じ

    f:id:mozy_ok:20190202162348p:plain
    テーブル構成

    f:id:mozy_ok:20190202162448p:plain
    iPhoneもきちんと認識されているぞ!!

  5. cloud_tabs テーブルの中身に目的のiPhoneで開いている数百のタブのリストがある!

    f:id:mozy_ok:20190202162732p:plain
    きたああああああーーーーー

  6. クエリを叩く select title, url from cloud_tabs

    f:id:mozy_ok:20190202162933p:plain
    実行した結果

  7. CSVに書き出して完了!!

    f:id:mozy_ok:20190202163136p:plain
    CSVが手に入った!

まとめ

意外と簡単にiPhoneで開いている数百のタブの情報がCSVでエクスポートできた!!
これでiPhoneのストレージの容量が減らせるぜ