/ Published in: Bash
A simple shell script wrapped around an applescript for piping text to Evernote. Try txt2evernote -h for options.
Expand |
Embed | Plain Text
#!/bin/bash osaopts= usage() { cat << EOF Usage: `basename $0` [options] file cat file | `basename $0` [options] OPTIONS: -h Show this message -t <title> Specify title of note -d <date> Specify creation date of note -t <tag(s)> Specify tags (separate with commas) -n <notebook> Specify notebook EOF } defined() { [ "${!1-X}" == "${!1-Y}" ] } # parse options while getopts "ht:d:k:n:" option do case $option in h) usage exit 1 ;; t) title=$OPTARG shift $((OPTIND-1)); OPTIND=1 ;; d) date=$OPTARG shift $((OPTIND-1)); OPTIND=1 ;; k) tags=$OPTARG shift $((OPTIND-1)); OPTIND=1 ;; n) notebook=$OPTARG shift $((OPTIND-1)); OPTIND=1 ;; ?) usage exit ;; esac done # pass options to osaopts if defined "title"; then osaopts="$osaopts title \"$title\"" fi if defined "date"; then osaopts="$osaopts created date \"$date\"" fi if defined "notebook"; then osaopts="$osaopts notebook \"$notebook\"" fi if defined "tags"; then tags=`echo "$tags" | perl -pe "s/,/\",\"/g"` osaopts="$osaopts tags {\"$tags\"}" fi # If no arguments, process STDIN if [ $# -eq 0 ]; then orig=`mktemp -t txt2evernote` cat > $orig elif [ -f "$@" ]; then # otherwise, arguments are file names orig="$@" else echo "$@ not a readable file" >&1 fi # Pass the goodies to osascript osascript <<EOF -- read file content set fileref_ to open for access "$orig" as POSIX file set text_ to read fileref_ as «class utf8» close access fileref_ -- send to Evernote tell application "Evernote" create note with text text_ $osaopts end tell EOF
You need to login to post a comment.
