Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Last active December 28, 2015 21:39
Show Gist options
  • Save seansullivan/7566587 to your computer and use it in GitHub Desktop.
Save seansullivan/7566587 to your computer and use it in GitHub Desktop.
Shell script for creating Markdown file from currently active tab and highlighted text in Google Chrome. Intent is to power a Jekyll <http://jekyllrb.com/> blog to replace my old Posterous site. Forked from Jekyll Bookmarklet <http://jonathanbuys.com/04-05-2011/Jekyll_Bookmarklet.html>
#!/bin/bash
TITLE=`osascript -e 'tell application "Google Chrome" \
to return title of active tab of front window'`
URL=`osascript -e 'tell application "Google Chrome" \
to return URL of active tab of front window'`
TEXT=`osascript -e 'tell application "Google Chrome" \
to execute the active tab of front window \
javascript "window.getSelection().toString();"'`
QUOTEDTEXT=`echo -n ">"; echo -n $TEXT`
LINK=`echo -n [$TITLE]; echo -n \($URL\)`
NAME=`echo $TITLE | sed s/\ /-/g`
USERNAME="seansullivan"
POSTNAME=`date "+%Y-%m-%d"-$NAME`
POST_FQN="/Users/$USERNAME/Projects/mysite/_posts/$POSTNAME.md"
touch $POST_FQN && /dev/null > $POST_FQN
echo "---" >> $POST_FQN
echo "layout: post" >> $POST_FQN
echo "title: $TITLE" >> $POST_FQN
echo "---" >> $POST_FQN
echo "" >> $POST_FQN
echo "$QUOTEDTEXT" >> $POST_FQN
echo "" >> $POST_FQN
echo "via: $LINK" >> $POST_FQN
/usr/bin/open $POST_FQN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment