Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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/"
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}
end tell
end if
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.