Skip to content

Commit

Permalink
.functions: Improve note
Browse files Browse the repository at this point in the history
Give the Notes.app function the ability to add both `title` and `body`.

Closes #203.
  • Loading branch information
sindresorhus authored and mathiasbynens committed May 10, 2013
1 parent 5a44681 commit b63c761
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions .functions
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,22 @@ function getcertnames() {
}

# Add note to Notes.app (OS X 10.8)
# Usage: `note 'foo'` or `echo 'foo' | note`
# Usage: `note 'title' 'body'` or `echo 'body' | note`
# Title is optional
function note() {
local text
if [ -t 0 ]; then # argument
text="$1"
else # pipe
text=$(cat)
local title
local body
if [ -t 0 ]; then
title="$1"
body="$2"
else
title=$(cat)
fi
body=$(echo "$text" | sed -E 's|$|<br>|g')
osascript >/dev/null <<EOF
tell application "Notes"
tell account "iCloud"
tell folder "Notes"
make new note with properties {name:"$text", body:"$body"}
make new note with properties {name:"$title", body:"$title" & "<br><br>" & "$body"}
end tell
end tell
end tell
Expand Down

0 comments on commit b63c761

Please sign in to comment.