Skip to content

Instantly share code, notes, and snippets.

@TakashiNakagawa
Last active August 1, 2017 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TakashiNakagawa/4700560 to your computer and use it in GitHub Desktop.
Save TakashiNakagawa/4700560 to your computer and use it in GitHub Desktop.
alfredからevernoteへポストする ノートブックはIdeas ノート名は日付 同一日付なら追記される
-- ノートブックの指定
property nb : "Ideas"
property _newNote : missing value
on alfred_script(q)
set _inputText to q
set AppleScript's text item delimiters to "-open"
set _text to text items of _inputText
set AppleScript's text item delimiters to "#"
set _item to text items of item 1 of _text
set _memo to text items of item 1 of _item
set _space to the rest of _item
set _tagList to {}
set AppleScript's text item delimiters to " "
repeat with tag in _space
set end of _tagList to item 1 of text items of tag
end repeat
set AppleScript's text item delimiters to ","
-- Evernote
tell application "Evernote"
if not (exists of notebook nb) then
create notebook nb
end if
set dateStr to do shell script "date +'%Y/%m/%d'"
set h to hours of (current date) as string
set m to minutes of (current date) as string
set h to text -2 thru -1 of ("0" & h)
set m to text -2 thru -1 of ("0" & m)
set timeStr to h & ":" & m & " -- "
set foundNotes to find notes "notebook:\"" & nb & "\"" & " intitle:\"" & dateStr & "\""
set found to ((length of foundNotes) is not 0)
if not found then
set _newNote to create note with text timeStr & _memo title dateStr notebook nb
else
repeat with curnote in foundNotes
set _newNote to curnote
tell _newNote to append text "\n\n" & timeStr & _memo
end repeat
end if
if (offset in _inputText of "-open") > 0 then
set _window to open note window with _newNote
activate _window
end if
end tell
end alfred_script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment