Skip to content

Commit

Permalink
Merge pull request #4 from eyalmazuz/master
Browse files Browse the repository at this point in the history
Added automatic sentence addition to Anki cards
  • Loading branch information
eshrh authored Nov 11, 2021
2 parents f3599ba + 1d6b783 commit b307cac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Ames automates the process of adding screenshots and desktop audio clips to your
+ `maim`: screenshots
+ `xdotool`: detecting active windows
+ `libnotify`: sending notifications
+ `xsel`: pasting clipboard content


## Installation
Expand All @@ -23,6 +24,7 @@ Ames automates the process of adding screenshots and desktop audio clips to your
* `sh ~/path/to/ames.sh -s`: prompt for an interactive screenshot selection
* `sh ~/path/to/ames.sh -a`: repeat the previous screenshot selection. If there is no previous selection, default to -s.
* `sh ~/path/to/ames.sh -w`: screenshot the currently active window (requires xdotool)
* `sh ~/path/to/ames.sh -c`: pasted the currently copied sentence in the clipboard (requires xsel)

### Arch users
1. Install the `ames` package from the AUR
Expand Down
29 changes: 28 additions & 1 deletion ames.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set -euo pipefail

AUDIO_FIELD="audio"
SCREENSHOT_FIELD="image"
SENTENCE_FIELD="Sentence"
# leave OUTPUT_MONITOR blank to autoselect a monitor.
OUTPUT_MONITOR=""
AUDIO_BITRATE="64k"
Expand Down Expand Up @@ -121,6 +122,25 @@ safe_request() {
gui_browse "nid:${newest_card_id:?Newest card is not known.}"
}

update_sentence() {
get_last_id
local update_request='{
"action": "updateNoteFields",
"version": 6,
"params": {
"note": {
"id": <id>,
"fields": { "<SENTENCE_FIELD>": "<sentence>" }
}
}
}'

update_request=${update_request/<id>/$newest_card_id}
update_request=${update_request/<SENTENCE_FIELD>/$SENTENCE_FIELD}
update_request=${update_request/<sentence>/$1}
safe_request "$update_request"
}

update_img() {
get_last_id
local update_request='{
Expand Down Expand Up @@ -275,18 +295,25 @@ record() {
fi
}

clipboard(){
local -r sentence=$(xsel -b)

update_sentence "${sentence}"
}

if [[ -z ${1-} ]]; then
usage
exit 1
fi

while getopts 'hrsaw' flag; do
while getopts 'hrsawc' flag; do
case "${flag}" in
h) usage ;;
r) record ;;
s) screenshot ;;
a) again ;;
w) screenshot_window ;;
c) clipboard ;;
*) ;;
esac
done

0 comments on commit b307cac

Please sign in to comment.