Skip to content

Instantly share code, notes, and snippets.

@scriptingosx
Created January 5, 2016 12:23
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save scriptingosx/74b3b4f086a49c136279 to your computer and use it in GitHub Desktop.
Save iCloud Tabs to Notes
property defaultAccountName : "iCloud"
property defaultFolderName : "Saved iCloud Tabs"
global html
global processedURLs
on appendLineWithURLItem(urlItem)
my appendHTML(" <li>")
my appendHTML("<a href=\"" & |url| of urlItem & "\">")
my appendHTML(|Title| of urlItem)
my appendHTML("</a></li>" & return)
set processedURLs to processedURLs & (|url| of urlItem)
end appendLineWithURLItem
on appendHTML(htmlString)
set html to html & htmlString
end appendHTML
on defaultFolder()
tell application "Notes"
if not (exists account defaultAccountName) then
display dialog "Cound not find account '" & defaultAccountName & "'!"
tell me to quit
end if
if exists folder defaultFolderName of account defaultAccountName then
return folder defaultFolderName of account defaultAccountName
end if
make new folder at account defaultAccountName with properties {name:defaultFolderName}
end tell
end defaultFolder
on run
set datestamp to "Saved on " & (short date string) of (current date) & " at " & (time string) of (current date) & return
set html to "<h1>" & datestamp & "</h1>" & return
set processedURLs to {}
tell application "System Events"
set SafariPrefsPlist to property list file "~/Library/SyncedPreferences/com.apple.Safari.plist"
repeat with x in every property list item of property list item "values" of SafariPrefsPlist
set v to property list item "value" of x
if exists property list item "Tabs" of v then
set deviceName to value of property list item "DeviceName" of v
my appendHTML("<h3>" & deviceName & "</h3>" & return)
my appendHTML("<ul>" & return)
set tabsPlist to value of property list item "Tabs" of v
repeat with i in tabsPlist
my appendLineWithURLItem(i)
end repeat
end if
my appendHTML("</ul>" & return)
end repeat
end tell
if (count of processedURLs) > 0 then
set f to my defaultFolder()
tell application "Notes"
make new note at f with properties {body:html, name:datestamp}
activate
end tell
end if
end run
@dotjay
Copy link

dotjay commented Oct 9, 2019

It seems that iCloud Tabs are no longer stored in ~/Library/SyncedPreferences/com.apple.Safari.plist
It looks like they've moved into ~/Library/Safari/CloudTabs.db

I've found this Alfred workflow works well for me:
https://github.com/kmarchand/iCloudTabsAlfredWorkflow

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