Created
October 16, 2025 10:21
-
-
Save mailinglists35/3957a8096a3fe03daced8df3d06355f1 to your computer and use it in GitHub Desktop.
view mac Safari history by time and date in Terminal with url and title
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
| #!/bin/bash | |
| #because Safari on mac has absolute crap history UI | |
| #thanks Microsoft Copilot | |
| PROFILE_DIR="$HOME/Library/Containers/com.apple.Safari/Data/Library/Safari/Profiles" | |
| declare -a UUIDS | |
| # Construim lista de profiluri | |
| i=0 | |
| for db in "$PROFILE_DIR"/*/History.db; do | |
| uuid=$(basename "$(dirname "$db")") | |
| UUIDS[i]="$uuid" | |
| ((i++)) | |
| done | |
| # Funcție: interogare CSV cu suport WAL | |
| query_history_csv() { | |
| local db="$1" | |
| local wal="$2" | |
| local sql="PRAGMA journal_mode=WAL; | |
| SELECT '\"' || datetime(history_visits.visit_time + 978307200, 'unixepoch', 'localtime') || '\",\"' || | |
| REPLACE(history_items.url, '\"', '\"\"') || '\",\"' || | |
| REPLACE(history_visits.title, '\"', '\"\"') || '\"' | |
| FROM history_visits | |
| JOIN history_items ON history_items.id = history_visits.history_item | |
| ORDER BY history_visits.visit_time DESC;" | |
| sqlite3 -readonly -noheader "$db" "$sql" | grep -v '^wal$' | |
| } | |
| # Non-interactiv: cu argument numeric | |
| if [[ "$1" =~ ^[0-9]+$ ]]; then | |
| index=$(( $1 - 1 )) | |
| selected_uuid="${UUIDS[$index]}" | |
| selected_db="$PROFILE_DIR/$selected_uuid/History.db" | |
| selected_wal="$PROFILE_DIR/$selected_uuid/History.db-wal" | |
| query_history_csv "$selected_db" "$selected_wal" | |
| exit 0 | |
| fi | |
| # Interactiv: preview CSV | |
| echo "🔍 Profiluri Safari disponibile (1 intrare per profil):" | |
| for idx in "${!UUIDS[@]}"; do | |
| db="$PROFILE_DIR/${UUIDS[$idx]}/History.db" | |
| entry=$(sqlite3 -readonly -noheader "$db" \ | |
| "SELECT '\"' || REPLACE(history_visits.title, '\"', '\"\"') || '\",\"' || | |
| REPLACE(history_items.url, '\"', '\"\"') || '\",\"' || | |
| datetime(history_visits.visit_time + 978307200, 'unixepoch', 'localtime') || '\"' | |
| FROM history_visits | |
| JOIN history_items ON history_items.id = history_visits.history_item | |
| ORDER BY history_visits.visit_time DESC LIMIT 1;") | |
| echo "$((idx+1)). ${UUIDS[$idx]} , $entry" | |
| done |
to run:
-interactively displays the profile list
-noninteractively with numeric argument of profile
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to check :
https://github.com/browser-history/browser-history
https://gist.github.com/lindeskar/347fd5da63b91a109d382500adc70960