I wanted the URL as well as window title, plus the ability to search or select etc which can be added in the query (illustrating mentionof google anywhere). In this instance I have remove any long tail of URL after ampersand (&) char. The tac puts it back in latest at the end order.
In terminal session:
sqlite3 ~/Library/Safari/History.db 'SELECT datetime(history_visits.visit_time+978307200, "unixepoch", "localtime"), history_visits.title || " @ " || substr(history_items.URL,1,max(length(history_items.URL)*(instr(history_items.URL,"&")=0),instr(history_items.URL,"&"))) as Info FROM history_visits INNER JOIN history_items ON history_items.id = history_visits.history_item where Info like "%google%" ORDER BY visit_time DESC LIMIT 30;'|tac
Reviewing browsing at a given past date involves time & date complexities but this may help, from a given date and time, edit2020-01-19 15:30 for your need...
sqlite3 ~/Library/Safari/History.db 'SELECT datetime(history_visits.visit_time+978307200, "unixepoch", "localtime"), history_visits.title || " @ " || substr(history_items.URL,1,max(length(history_items.URL)*(instr(history_items.URL,"&")=0),instr(history_items.URL,"&"))) as Info FROM history_visits INNER JOIN history_items ON history_items.id = history_visits.history_item where history_visits.visit_time>(julianday("2020-01-19 15:30")*86400-211845068000) ORDER BY visit_time ASC LIMIT 30;'
Giving output like:
2020-01-20 16:35:15|Amazon.co.uk: carborundum wheel @ https://www.amazon.co.uk/s/ref=nb_sb_noss_1?url=search-alias%3Daps&
2020-01-20 16:35:15|Amazon.co.uk: carborundum wheel @ https://www.amazon.co.uk/s?k=carborundum+wheel&
2020-01-20 16:35:41|Multi-Sharp 1301 Rotary Mower/Garden Tool Sharpener: Amazon.co.uk: Garden & Outdoors @ https://www.amazon.co.uk/Multi-Sharp-Rotary-Mower-Garden-Sharpener/dp/B0001OZH6M/ref=sr_1_11?keywords=carborundum+wheel&
2020-01-20 16:37:14|Amazon.co.uk: grinding wheel @ https://www.amazon.co.uk/s?k=grinding+wheel&
2020-01-20 16:39:26|Amazon.co.uk: grinding wheel @ https://www.amazon.co.uk/s?k=grinding+wheel&
2020-01-20 16:39:26|Amazon.co.uk: grinding wheel @ https://www.amazon.co.uk/s?k=grinding+wheel&
2020-01-20 16:40:15|FERM BGA1057 Grind Stone: Amazon.co.uk: DIY & Tools @ https://www.amazon.co.uk/Ferm-BGA1057-FERM-Grind-Stone/dp/B00AW9GVO8/ref=sr_1_71?keywords=grinding+wheel&
One last note, if you open a sqlite3 session to do lots of queries I found that the database does not seem to update if you continue to use Safari. Maybe a snapshot copy is used? (This on El Capitan. If you have to make a file copy on later OS versions obviously no updates show!)
> ~/SafariHist.txt
to the end of this command, it will output directly to a file in your home directory. Useful for exporting / viewing thousands of entries. Great tip, your work was very helpful! – Demis Jun 29 '21 at 20:33select datetime(visit_time + 978307200, 'unixepoch', 'localtime') as 'Visit Time',
…. The constant978307200
is the difference in seconds between the Unix epoch (1970-01-01) and Apple's epoch (2001-01-01). – Dave Land Aug 10 '21 at 04:38Could not open database file. Reason: unable to open database file
. – alper Jul 21 '22 at 10:33