Skip to content

Instantly share code, notes, and snippets.

@Aneureka
Last active January 25, 2025 03:24
Show Gist options
  • Save Aneureka/41e4ee6ecb797bc97d20a44927d3dcbe to your computer and use it in GitHub Desktop.
Save Aneureka/41e4ee6ecb797bc97d20a44927d3dcbe to your computer and use it in GitHub Desktop.
An apple script to sync history, bookmarks & passwords from google chrome to safari.
# Add a scheduled sync task at 4:00 am
# Some privileges should be granted to `cron` *manually*, so you may test `* * * * *` (run every second) first to grant the needed privileges in advance
0 4 * * * osascript /path/to/your/sync-from-chrome-to-safari.scpt
-- close google chrome to perform importing
do shell script "killall \"Google Chrome\" || echo \"Google Chrome is not running.\""
do shell script "killall Safari || echo \"Safari is not running.\""
tell application "Safari" to activate
tell application "System Events" to set visible of application process "Safari" to false
-- import history, bookmarks, passwords from google chrome to safari
tell application "System Events" to tell process "Safari"
delay 0.5
log "Syncing..."
tell menu item "Import From" of menu "File" of menu bar item "File" of menu bar 1
tell menu "Import From"
click menu item "Google Chrome.app…"
end tell
end tell
keystroke return
log "Complete sync"
end tell
-- close safari
do shell script "killall Safari || echo \"Safari is not running.\""
-- restore chrome closed tabs and minimize window in background
delay 0.5
log "Opening chrome in background"
do shell script "open -a \"Google Chrome\" --args --restore-last-session --no-startup-window"
@frantortosa
Copy link

Oh, I had actually given up on this, so I am grateful you provided that link. I will definitely try it out now.

@sohojmanush
Copy link

Been looking for this for so long. I think the script can be executed by Automator instead of chron. Can you add the option to import specifically? Like, I want to import only Bookmarks and History.

@sagoez
Copy link

sagoez commented Aug 4, 2024

Did someone get this error too?

execution error: System Events got an error: Can’t get menu item "Google Chrome.app…" of menu "Import From" of menu item "Import From" of menu "File" of menu bar item "File" of menu bar 1 of process "Safari". (-1728)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment