aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSindre Sorhus <sindresorhus@gmail.com>2012-07-29 17:05:18 +0200
committerMathias Bynens <mathias@qiwi.be>2012-07-31 20:41:43 +0200
commit8ed0257572cf00acd94c9768dc10f9f7e660cf0b (patch)
tree737e167770d2f9a174a2d0671942917c079cfd86
parent5c3306ce4d5a0944babc13b10e766b926ec03cb2 (diff)
downloaddotfiles-8ed0257572cf00acd94c9768dc10f9f7e660cf0b.tar.gz
dotfiles-8ed0257572cf00acd94c9768dc10f9f7e660cf0b.tar.bz2
dotfiles-8ed0257572cf00acd94c9768dc10f9f7e660cf0b.zip
.functions: Add `note` and `remind`
`note` quickly adds a note to Notes.app, and `remind` adds a reminder to — you guessed it — Reminders.app. Both applications are available on OS X 10.8. Note that in order for `note` to work, iCloud sync must be enabled for Notes.app.
-rw-r--r--.functions48
1 files changed, 43 insertions, 5 deletions
diff --git a/.functions b/.functions
index a544dfd..45100d6 100644
--- a/.functions
+++ b/.functions
@@ -45,13 +45,12 @@ function gurl() {
}
# Syntax-highlight JSON strings or files
+# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json`
function json() {
- if [ -p /dev/stdin ]; then
- # piping, e.g. `echo '{"foo":42}' | json`
- python -mjson.tool | pygmentize -l javascript
- else
- # e.g. `json '{"foo":42}'`
+ if [ -t 0 ]; then # argument
python -mjson.tool <<< "$*" | pygmentize -l javascript
+ else # pipe
+ python -mjson.tool | pygmentize -l javascript
fi
}
@@ -78,6 +77,45 @@ function codepoint() {
echo # newline
}
+# Add note to Notes.app (OS X 10.8)
+# Usage: `note 'foo'` or `echo 'foo' | note`
+function note() {
+ local text
+ if [ -t 0 ]; then # argument
+ text="$1"
+ else # pipe
+ text=$(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"}
+ end tell
+ end tell
+end tell
+EOF
+}
+
+# Add reminder to Reminders.app (OS X 10.8)
+# Usage: `remind 'foo'` or `echo 'foo' | remind`
+function remind() {
+ local text
+ if [ -t 0 ]; then
+ text="$1" # argument
+ else
+ text=$(cat) # pipe
+ fi
+ osascript >/dev/null <<EOF
+tell application "Reminders"
+ tell the default list
+ make new reminder with properties {name:"$text"}
+ end tell
+end tell
+EOF
+}
+
# Manually remove a downloaded app or file from the quarantine
function unquarantine() {
for attribute in com.apple.metadata:kMDItemDownloadedDate com.apple.metadata:kMDItemWhereFroms com.apple.quarantine; do