Save iCloud Tabs to Notes
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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