Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tzarskyz/5559497 to your computer and use it in GitHub Desktop.
Save tzarskyz/5559497 to your computer and use it in GitHub Desktop.
on replaceCommasInStringWithHTMLEntity(theTitle)
set rubyCommand to quote & "puts " & "'" & theTitle & "'" & ".gsub( /,/, ',' )" & quote
set strippedTitle to do shell script "ruby -e " & rubyCommand
return strippedTitle
end replaceCommasInStringWithHTMLEntity
on stripUTMFromURL(urlToStrip)
set rubyCommand to quote & "puts " & "'" & urlToStrip & "'" & ".gsub( /\\?utm.*$/, '' )" & quote
set strippedURL to do shell script "ruby -e " & rubyCommand
return strippedURL
end stripUTMFromURL
tell application "Safari"
set pageTitle to name of document 1
set currentURL to URL of current tab of window 1
set selectedText to (do JavaScript "window.getSelection().toString()" in document 1)
end tell
set pageTitle to replaceCommasInStringWithHTMLEntity(pageTitle)
set currentURL to stripUTMFromURL(currentURL)
set theDate to current date
return "---" & "
" & "layout: post" & "
" & "title: " & "\"" & pageTitle & "\"" & "
" & "date: " & (do shell script "date +%Y") & "-" & (do shell script "date +%m") & "-" & (do shell script "date +%d") & " " & (do shell script "date +%H") & ":" & (do shell script "date +%M") & "
" & "comments: true" & "
" & "categories: " & "
" & "- " & "
" & "external-url: " & currentURL & "
" & "---" & "
" & "
" & "> " & selectedText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment