26

I'm trying to figure out how to determine the time websites were visited in the Safari history. (I can't imagine why this isn't easy to do like in every other browser I've ever used).

NOTE: I'm running Safari 9.0.3 and El Capitan 10.11.3.

I've done some research and found some files in ~/Library/Safari. The file History.db file looks possibly promising but I haven't been able to figure out how to find the timestamp from this yet.

16

I just tried this in 10.11.4 and it works; you can see the history. If someone clears the cache, this goes away.

Go to the following location:

/Users/yourname/Library/Caches/Metadata/Safari/History/

From here you can change the view to List View and sort by Date Modified.

| improve this answer | |
28

So I woke up today to my sleep-tracker app telling me I went to bed an hour earlier than I thought I did, so naturally I assumed the app was the one who made the stupid mistake. Luckily I'd surfed the web before going to bed, but apparently Apple changed things up again as of High Sierra or Safari 11 so the other answers didn't work for me.

I found out how to get the visit times, and since I went way to far to get to the bottom of this highly unimportant issue already, I thought I'd share my findings here:

Edit

Okay so I got carried away a little more and wrote a bash one-liner to do all the hard work for you. Just open the terminal and copy-past it in. It should work without having to install anything, unless apple has changed something again in the mean time.

You can ignore the empty lines in the output (they are http-redirects) and you can change the last number 30 in the command to filter the number of lines you want to see.

sqlite3 ~/Library/Safari/History.db 'select visit_time,title from history_visits order by visit_time desc;' \
 | while read i; do d="${i%%.*}"; echo "$(date -r $((d+978307200))) | ${i#*|}"; done \
 | head -n 30

Original answer

So instead of having a simple folder with all the history like before, they now write the history into a database. Here's how you get the info if you really want to:

  1. The data is now stored in an SQLite Database, so you're gonna need some tool to read that. I suggest the DB Browser for SQLite. Just install it the usual way.
  2. Now open the database file. It is located here: /Users/[yourname]/Library/Safari/History.db.
  3. In the Browse Data Tab click the Table: dropdown and select history_visits. History_visits screenshot
  4. Now, sort by visit_time and find the thing you are interested in.
  5. Those numbers under the visit_time column are a Core Data Timestamp, so to get something human-readable you need a converter. Simply use this one: https://www.epochconverter.com/coredata

Hope this solves your history-related conundrum.

| improve this answer | |
  • 1
    You are awesome mate!! Works like a charm in Mojave too!! – Jeeva Dec 20 '18 at 6:02
  • 2
    The other solutions werent working on mojave but this works great!! Thank you so much mate :) – Flaming_Dorito Feb 24 '19 at 23:12
  • If it fails just copy the database file to another place, or maybe closing safari is sufficient – Simon Mar 27 '19 at 22:54
11

I modified the oneliner that meonlol gave above. This way it is just pure SQL query.

sqlite3 ~/Library/Safari/History.db \
    'SELECT datetime(visit_time+978307200, "unixepoch", "localtime"), title
     FROM history_visits
     ORDER BY visit_time DESC
     LIMIT 30;'

In Mojave, and possibly later, accessing the file in terminal seems limited. Either grant full access to Terminal in System Preferences or use Finder to open ~/Library/Safari and then copy History.db to somewhere else.

| improve this answer | |
  • 1
    +1 on copying the database to a location outside of the Library tree (at least in Mojave). Seems a required step to access the database. – DaveL17 May 20 '19 at 11:53
  • 1
    You still can access the file on Mojave if you grant Terminal full access in System Preferences. – nohillside May 26 '19 at 12:23
1

This path has changed in Sierra

In 10.12.6 go to

/Users/yourname/Library/Caches/Metadata/Safari/History

| improve this answer | |
1

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!)

| improve this answer | |
0

In Sierra now just use Finder to search for a folder called Safari, then go into the History folder, and you can change the view as mentioned before.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .