Created
November 9, 2009 07:15
-
-
Save ttscoff/229757 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
#!/usr/bin/env osascript | |
-- For more info, see http://brettterpstra.com | |
-- Surf Saver 1.0 | |
-- Saves tabs from Safari window to a dated page in VoodooPad, with a timestamp for the link group. | |
-- format of output is templatable below, defaults to markdown list. | |
-- | |
-- Script by Brett Terpstra | |
-- http://brettterpstra.com | |
-- built off of the amazing Scratchpad scripts by Ian Beck | |
-- http://tagamac.com/scratchpad/ | |
-- Name of page to append bookmarks to | |
property _docname : "Brainstorming" | |
-- Link template, applied per tab retrieved, with a newline automatically added | |
-- variables are %name and %url | |
property _template : "* [%name](%url)" | |
-- property _template : "%name - %url" | |
-- property _template : "%url - \"%name\"" | |
on append_bookmarks(logText) | |
-- Init | |
set shortDate to do shell script "date '+%Y-%m-%d'" | |
set curDate to "Bookmarks " & shortDate | |
set prettyDate to do shell script "date '+%A, %B %d, %Y'" | |
set curTime to do shell script "date '+%l:%M %p'" | |
-- Check to see if we've got text, ask for it if not | |
if logText is equal to "" then | |
return false | |
end if | |
-- Find the Scratchpad | |
set scratchDoc to "" | |
tell application "VoodooPad Pro" | |
-- This is the sketchiest stuff, so catch errors | |
try | |
set openDocs to documents | |
repeat with idx from 1 to number of items in openDocs | |
set docName to name of item idx of openDocs | |
if docName contains _docname then | |
set scratchDoc to item idx of openDocs | |
exit repeat | |
end if | |
end repeat | |
if scratchDoc is not equal to "" then | |
set logText to curTime & return & logText & return & "---" & return & return | |
if not (exists page curDate of scratchDoc) then | |
tell scratchDoc to create new page with name curDate with content "===== " & prettyDate & " =====" & return & return | |
tell page curDate of scratchDoc to add category named "bookmarks" | |
end if | |
-- Append the log text | |
tell page curDate of scratchDoc to append text logText | |
else | |
-- Couldn't find the scratchpad | |
error "Error: Bookmark target is not open" | |
return false | |
end if | |
on error errStr number errNum | |
error errStr number errNum | |
end try | |
end tell | |
end append_bookmarks | |
--search and replace function for template | |
on snr(tofind, toreplace, TheString) | |
set ditd to text item delimiters | |
set text item delimiters to tofind | |
set textItems to text items of TheString | |
set text item delimiters to toreplace | |
if (class of TheString is string) then | |
set res to textItems as string | |
else -- if (class of TheString is Unicode text) then | |
set res to textItems as Unicode text | |
end if | |
set text item delimiters to ditd | |
return res | |
end snr | |
tell application "Safari" | |
set tabList to every tab of front window | |
set urlList to "" | |
repeat with aTab in tabList | |
-- set aLink to "* " & name of aTab & " - " & URL of aTab & return | |
set aLink to _template | |
set aLink to my snr("%name", name of aTab, aLink) | |
set aLink to my snr("%url", URL of aTab, aLink) | |
set urlList to urlList & aLink & return | |
end repeat | |
my append_bookmarks(urlList) | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment