Created
March 6, 2010 23:33
-
-
Save ttscoff/324014 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby -rjcode -Ku | |
# From a TextMate command, but without TextMate-specific environment variables. | |
# Still works in TextMate, but makes a good Snow Leopard service as well. | |
# requires that MultiMarkdown be installed in ~/Library/Application Support/MultiMarkdown | |
# That, or edit the script to point to yours :) | |
input = STDIN.read | |
contents = '' | |
tags = '' | |
title = nil | |
def e_as(str) | |
str.to_s.gsub(/(?=["\\])/, '\\') | |
end | |
input.each_line { |line| | |
if line =~ /^# (.*?)/ | |
title = line[2..-1] | |
break | |
end | |
} | |
title = %x{date '+Clipped note: %A, %B %d, %Y at %l:%M %p'|tr -s " "} if title.nil? | |
input.each_line { |line| | |
if line =~ /^[Tt]ags: / | |
tags = line[5..-1].split(',').map {|tag| tag = tag.strip.gsub(/^(.)?\b|\b(.)?$/,"\\2\"\\1") } | |
break | |
end | |
} | |
IO.popen('"$HOME/Library/Application Support/MultiMarkdown/bin/MultiMarkdown.pl"|"$HOME/Library/Application Support/MultiMarkdown/bin/SmartyPants.pl"', "r+") do |io| | |
input.each_line { |line| | |
io << line unless line =~ /^# |[Tt]ags\: / | |
}; io.close_write | |
io.each_line do |line| | |
contents << line | |
end | |
end | |
tags = " tags {#{tags.join(",")}}" unless tags.empty? | |
%x{osascript -e 'tell application "Evernote" to create note with html "#{e_as contents}" title "#{title}" notebook "Unfiled"#{tags}'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment