Skip to content

Instantly share code, notes, and snippets.

@Aneureka
Last active November 4, 2023 13:13
Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • 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

frantortosa commented Feb 10, 2021

It seems this is exactly what I was looking for. Sorry, I am a newbie to cron for scheduling the task, a quick explanation or some link could help ... thanks in advance!

@gkb21
Copy link

gkb21 commented May 1, 2021

It seems this is exactly what I was looking for. Sorry, I am a newbie to cron for scheduling the task, a quick explanation or some link could help ... thanks in advance!

Yeah same, Would someone be able to explain how to get this running ?

@lzl19900514
Copy link

怎么样从edge同步到Safari啊?现在edge用户群也挺大的。直接把脚本里面的Google Chrome改成Microsoft Edge并不行

@gitatmax
Copy link

I'm sure it's safe to assume you both (@gkb21 & @frantortosa) got this figured by now but, but if not or for anyone else who may be interested, here is an example of setting up automated tasks/jobs in macOS & Linux. I hope it helps!

@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.

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