How to backup and access iOS Safari's reading list?
Assuming you have your backup under $backup_dir
, the reading list is stored in the sqlite database file $backup_dir/Library/Safari/Bookmarks.db
, under the table bookmarks
.
This table also contains favourites, which can be distinguished from reading list bookmarks by the fact they have no value for the column extra_attributes
. Therefore, we can use the following query:
select url,title
from bookmarks
where url not like '' and extra_attributes not like '';
To import these in browsers, we can transform the entries into Netscape Bookmark File Format. You can use, for example, the following AWK script:
#!/usr/bin/awk -f
BEGIN { print \
"<!DOCTYPE NETSCAPE-Bookmark-file-1>\n" \
"<!--This is an automatically generated file.\n" \
"It will be read and overwritten.\n" \
"Do Not Edit! -->\n" \
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n" \
"<TITLE>Bookmarks</TITLE>\n" \
"<H1>Bookmarks</H1>\n" \
"<DL><p>"
}
/^[[:space:]]*$/ { next }
{
split($0, parts, "|")
url = parts[1]
title = separator = ""
for (i=2; i in parts; i++) {
title = title separator parts[i]
separator = "|"
}
print "<DT><A HREF=\"" url "\">" title "</A>"
}
END { print "</DL><p>" }
In sum, you can do all this with the following bash "one-liner":
echo "
select url,title
from bookmarks
where url not like '' and extra_attributes not like '';
" | \
sqlite "$backup_dir"/Library/Safari/Bookmarks.db | \
./"$awk_script" > bookmarks.html