Created
July 19, 2025 19:13
-
-
Save SHi-ON/8723a22783cac80089250400f6b4dad7 to your computer and use it in GitHub Desktop.
Quickly preview your recent Safari browsing history (last 50 visits) in macOS using Quick Look, with automatic cleanup for repeat use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my_activity_safari.sh | |
# | |
# Function: myActivitySafari | |
# | |
# Description: | |
# Preview your 50 most recent Safari browsing history entries on macOS, | |
# using Quick Look. This function queries Safari’s local SQLite history, | |
# previews the results, and removes the temporary file so it can be run | |
# again without file conflicts. | |
# | |
# Usage: | |
# - Copy this function to your ~/.zshrc or ~/.bashrc | |
# - Source your shell config: source ~/.zshrc | |
# - Run `myActivitySafari` from the terminal | |
myActivitySafari() { | |
# Create a temporary file for output | |
tmpfile=$(mktemp /tmp/myActivitySafari_SHi-ON.txt) | |
# Query the Safari history database for the 50 most recent visits | |
sqlite3 -header -column ~/Library/Safari/History.db \ | |
"SELECT datetime(visit_time + 978307200, 'unixepoch', 'localtime') AS visit_date, url | |
FROM history_visits | |
JOIN history_items ON history_items.id = history_visits.history_item | |
ORDER BY visit_date DESC | |
LIMIT 50;" > "$tmpfile" | |
# Preview the result using Quick Look | |
qlmanage -p "$tmpfile" | |
# Remove the temporary file after preview, | |
# so the command can run again without temp file creation conflict | |
rm "$tmpfile" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment