Skip to content

Instantly share code, notes, and snippets.

@alexz12948
Created February 13, 2023 19:46
Show Gist options
  • Save alexz12948/f2e1427a2c75d1bdbe0d6d3aae12a1eb to your computer and use it in GitHub Desktop.
Save alexz12948/f2e1427a2c75d1bdbe0d6d3aae12a1eb to your computer and use it in GitHub Desktop.
Prints out the dates/times for the most recently visited pages in Safari
#!/bin/bash
: << FILE_HEADER
Name: Alexander Zsikla
Date: Feb 2023
Prints out the dates/times for the most recently visited pages in Safari
We are just performing a sqlite3 query against the safari history database
and parsing out the seconds and the webpage title and printing it out in
an easy to read format
Example row from table: 698008718.214614|Operations on variables
Becomes: Mon Feb 13 14:18:38 EST 2023 | Operations on variables
USAGE
-----
Update the variable NUM_ROWS to the number of rows you want retrieved and run
`./get_safari_history` in the terminal
FILE_HEADER
EPOCH=978307200 # Add this to get time to present day
NUM_ROWS=50
QUERY="SELECT visit_time,title FROM history_visits ORDER BY visit_time DESC LIMIT $NUM_ROWS;"
sqlite3 ~/Library/Safari/History.db "$QUERY" | \
while read row; do
seconds="${row%%.*}"
title="${row#*|}"
echo "$(date -r $((seconds + EPOCH))) | $title"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment