Created
August 29, 2016 15:06
-
-
Save scriptingosx/52ebbb2e3d030b53556f48c90df0a5e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
global html | |
global processedURLs | |
on appendLineWithDoc(theDoc) | |
tell application "Safari" | |
tell theDoc | |
try | |
my appendHTML(" <li>") | |
my appendHTML("<a href=\"" & URL & "\">") | |
my appendHTML(name) | |
my appendHTML("</a></li>" & return) | |
set processedURLs to processedURLs & (URL as string) | |
end try | |
end tell | |
end tell | |
end appendLineWithDoc | |
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 | |
my appendHTML("<ul>" & return) | |
set processedURLs to {} | |
tell application "Safari" | |
activate | |
set w to window 1 | |
set n to 0 | |
try -- this will fail for the downloads window | |
set n to count tabs of w | |
end try | |
if n > 1 then | |
repeat with t in every tab of w | |
my appendLineWithDoc(t) | |
end repeat | |
else if n = 1 then | |
my appendLineWithDoc(document of w) | |
end if | |
end tell | |
my appendHTML("</ul>" & return) | |
if (count of processedURLs) > 0 then | |
do shell script "echo " & quoted form of html & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf" | |
end if | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment