注意:這篇主要探討的是閱讀列表在macOS的Safari被誤刪的救援,並非iOS的閱讀列表救援
在一天晚上TK正閒得發慌,準備要整理閱讀列表的時候,不小心手賤的按下了『清除所有項目』….然後又邊講電話的邊按下確認視窗上的確認…


於是我馬上開始爬相關的救援文章,大多都是for iOS的,中文沒有找到for macOS的讓我真的失望…
不過有爬到使用TimeMachine來恢復的相關文章:
Reading List – how to restore it
首先進入這個路徑:
~/Library/Safari/
然後打開TimeMachine




他回來之後大概三秒又全部消失了…為什麼呢?
原來是iCloud的同步機制——只要你的網路是連接狀態,他會不斷的確認你的閱讀列表是與其他裝置保持同步的狀態,所以剛剛刪除了所有的裝置都清除之後當然電腦端恢覆iCloud又會將它清空囉!
且Bookmarks.plist檔沒辦法被直接編輯…
那該怎麼辦呢?所幸TK爬文找到了alexwlchan這位大神利用Python寫了一隻匯出Safari閱讀列表的小程式,只要安裝了Python就能執行它唷!
以下是Python source code:
import os import plistlib INPUT_FILE = os.path.join(os.environ['HOME'], 'Library/Safari/Bookmarks.plist') OUTPUT_FILE = 'readinglist.txt' # Load and parse the Bookmarks file with open(INPUT_FILE, 'rb') as plist_file: plist = plistlib.load(plist_file) # Look for the child node which contains the Reading List data. # There should only be one Reading List item children = plist['Children'] for child in children: if child.get('Title', None) == 'com.apple.ReadingList': reading_list = child # Extract the bookmarks bookmarks = reading_list['Children'] # For each bookmark in the bookmark list, grab the URL urls = (bookmark['URLString'] for bookmark in bookmarks) # Write the URLs to a file with open(OUTPUT_FILE, 'w') as outfile: outfile.write('\n'.join(urls))
當然也可以直接下載py檔
download the script
在執行它之前請先確保網路是斷線的,然後使用TimeMachine先將Bookmarks.plist檔案回復到之前的版本




最後再將這些網址一個一個拉回閱讀列表囉!雖然這個方法很費工但現階段好像只能這樣了…TK尚未找到更好的辦法,所以有待網友幫忙囉哈哈