Skip to content

Instantly share code, notes, and snippets.

@fractaledmind
Created July 24, 2013 04:51
Show Gist options
  • Save fractaledmind/6068151 to your computer and use it in GitHub Desktop.
Save fractaledmind/6068151 to your computer and use it in GitHub Desktop.
This is a fork of my other script to create a new TextMate note. Since the free TextMate2 does not support the "insert" command, I created a work-around using the clipboard.
(* CREATE NEW NOTE IN TEXTMATE (FOR EXPORT TO EVERNOTE)
-- created by Stephen Margheim
-- 07 July 2013
-- open source
REQUIRED PROGRAMS:
-- TextMate (I have alternate code for TextEdit as well)
This script prompts you for a Note title and generates a note with that title and opens it in TextMate2. This note will reside in a folder on your Desktop called "Pre-Evernote". If you do not have such a folder, the script creates it. Since I create the new note via the Terminal, which requires single word titles, there is a precaution to replace spaces with underscores.
As I use Evernote to "host" my HTML notes, I also add the relevant MetaData to export the plain text to Evernote via the Markdown2Evernote python script discussed here (http://blog.timlockridge.com/blog/2013/02/03/using-textmate-and-markdown-with-evernote-configuring-a-workflow/).
*)
display dialog "Note Title?" default answer "" with title "New Pre-Evernote Markdown File"
set theTitle to text returned of result
--if the title is multiple words, replace spaces with underscores.
set finalTitle to my Spaces2Underscors(theTitle)
--create and open new note
tell application "Terminal"
do script "cd Desktop/; mkdir Pre-Evernote; cd Pre-Evernote/; touch " & finalTitle & ".md; open -a TextMate " & finalTitle & ".md"
delay 0.3
quit
end tell
(* If you don't have TextMate, here's the Terminal code for TextEdit. To switch them out, uncomment this code and delete above. *)
--tell application "Terminal"
--do script "cd Desktop/; mkdir Pre-Evernote; cd Pre-Evernote/; touch " & finalTitle & ".md; open -a TextEdit " & finalTitle & ".md"
--delay 0.3
--quit
--end tell
--establish a variable for the line feed (aka LF key)
set LF to ASCII character 10
--insert the MetaData for export to Evernote
set FinalText to "# " & theTitle & LF & "= !nbox" & LF & LF & "**" & theTitle & "**" & LF & LF
tell application "TextMate"
set the clipboard to FinalText
tell application "System Events"
keystroke "v" using {command down}
end tell
end tell
(* If you don't have TextMate, here's alternate code for TextEdit. To switch them out, uncomment this code and delete above. *)
--tell application "TextEdit"
-- activate
-- make new word at end of text of document 1 with data FinalText
--end tell
(* HANDLERS *)
on Spaces2Underscors(theName)
set tid to AppleScript's text item delimiters
if theName contains " " then
set AppleScript's text item delimiters to " "
set nameList to text items of theName
set AppleScript's text item delimiters to "_"
set newname to (nameList as string)
set AppleScript's text item delimiters to tid
else
set newname to theName
end if
if newname contains "-" then
set AppleScript's text item delimiters to "-"
set nameList to text items of newname
set AppleScript's text item delimiters to "_"
set finalName to (nameList as string)
set AppleScript's text item delimiters to tid
else
set finalName to newname
end if
return finalName
end Spaces2Underscors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment