Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function wait_for_window_to_activate() {
- # first parameter - window title or part of the window title
- window_title="$1"
- time_sec=900
- while [[ 0 -ne $time_sec ]]; do
- echo "$time_sec, waiting... to activate"
- time_sec=$[$time_sec-1]
- xdotool search --onlyvisible --name "$window_title" windowactivate
- if [[ $? == 0 ]]; then
- sleep 0.5
- window_name=$(xdotool getwindowfocus getwindowname)
- if echo $window_name | grep -q "$window_title" ; then
- echo "window active "$window_name
- break
- fi
- fi
- sleep 0.5
- done
- }
- function wait_for_window_to_close() {
- # first parameter - window title or part of the window title
- window_title="$1"
- time_sec=900
- while [[ 0 -ne $time_sec ]]; do
- echo "$time_sec, waiting... to close"
- sleep 1
- time_sec=$[$time_sec-1]
- xdotool search --onlyvisible --name "$window_title" windowactivate
- if ! [[ $? == 0 ]]; then
- echo "window closed"
- break
- fi
- done
- }
- function type_enter() {
- # first parameter - window title or part of the window title
- string_to_write="$1"
- xdotool type $string_to_write
- sleep 0.5
- xdotool key Return
- }
- function mousemove_mouseclick() {
- window_title="$1"
- relative_coord_x="$2"
- relative_coord_y="$3"
- mouse_click_type="$4"
- xdotool search --sync --onlyvisible --name $window_title windowactivate
- sleep 0.5
- window_coord=$(xdotool search --sync --onlyvisible --name "$window_title" getwindowgeometry --shell)
- eval $window_coord
- # let X+=80
- # let Y+=116
- let X+=relative_coord_x
- let Y+=relative_coord_y
- xdotool mousemove $X $Y click $mouse_click_type
- }
- function repeat_send_key() {
- window_title="$1"
- key="$2"
- repeat="${3:-1}"
- xdotool search --onlyvisible --name "$window_title" windowactivate
- if [[ $? == 0 ]]; then
- for (( i=1; i <= repeat; i++ ))
- do
- xdotool key $key
- sleep 0.1
- done
- fi
- }
- function tranquility_save() {
- # Tranquility Reader addon
- # Tranquility Reader improves the readability of web articles by removing unnecessary elements
- wait_for_window_to_activate "Dissenter"
- # echo $(date '+%Y %b %d %H:%M')
- mousemove_mouseclick "Dissenter" 1412 74 1
- sleep 5
- # first type
- win_title=$(echo $(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) _NET_WM_VISIBLE_NAME) | cut -d '=' -f 2 | sed s/' "'//g | sed s/' - Dissenter"'//g)
- echo $win_title
- # correct title
- escape=("[" "]" "~" "!" "{" "}" "(" ")" "$" "@" "<" ">" ":" ";" "," '`' "%" "+" "=" '"' "|" "?" '*' "&" "'")
- for e in "${escape[@]}"
- do
- win_title=${win_title//[$e]/}
- done
- win_title=$(echo $win_title | sed -e 's/[[:space:]]\+/ /g')
- win_title=${win_title//" "/"_"}".txt"
- echo $win_title
- # write to clipbaord
- xdotool key ctrl+a
- sleep 0.5
- xdotool key ctrl+c
- sleep 0.5
- clip_read=$(xsel -b)
- echo "$clip_read" >> /media/ramdisk/recordings/$win_title
- echo "done"
- # save page SingleFile second type
- # wait_for_window_to_activate "Dissenter"
- # xdotool key ctrl+shift+y
- # win_title="Save File"
- # wait_for_window_to_activate "$win_title"
- # sleep 0.5
- # xdotool keydown ctrl && sleep 0.2 && xdotool key l && xdotool keyup ctrl
- # sleep 0.5
- # xdotool keydown ctrl && sleep 0.2 && xdotool key Home && xdotool keyup ctrl
- # sleep 0.5
- # type_enter $(echo ~/Downloads/reading/)
- # wait_for_window_to_close "$win_title"
- }
- function open_ebook() {
- pdfxchange_dir_loc=$(echo ~/progs/pdfxchange)
- pdfxchange_run_loc="/media/ramdisk/pdfxchange/PDFXEdit.x64.exe"
- ramdisk_loc="/media/ramdisk"
- win_title="Archivarius 3000"
- wait_for_window_to_activate "$win_title"
- echo -n "" | xclip -selection clipboard
- repeat_send_key "$win_title" "Shift+F10"
- sleep 0.5
- repeat_send_key "$win_title" "Up" 3
- repeat_send_key "$win_title" "Right"
- repeat_send_key "$win_title" "Down"
- repeat_send_key "$win_title" "Return"
- clip_read=$(xsel -b)
- if [[ ! $clip_read == "" ]]; then
- first_trim=${clip_read#*$'\n'}
- result=$(echo $clip_read | grep -Ei '.epub')
- if [[ -n $result ]]; then
- echo "epub detected"
- file_name=${first_trim##*"Z:"}
- file_name=${file_name%".epub"*}".epub"
- file_loc=${file_name//\\//}
- else
- echo "other formats"
- file_name=${first_trim%"%"*}
- file_name=$(echo "$file_name" | sed 's/[[:blank:]]/ /g' | awk '{$1=$1};1')
- file_name=${file_name%" "*}
- second_trim=${first_trim#*%}
- sufix=${second_trim##*\\}
- file_folder=${second_trim%"$sufix"*}
- file_folder=${file_folder##*"Z:"}
- file_folder=${file_folder//\\//}
- file_loc=$file_folder$file_name
- fi
- escape=("[" "]" "~" "!" "{" "}" "(" ")" "$" "@" "<" ">" ":" ";" "," '`' "%" "+" "=" '"' "|" "?" '*' "&" " " "'")
- for e in "${escape[@]}"
- do
- file_loc=${file_loc//[$e]/\\$e}
- done
- file_loc=${file_loc//"\\'"/"'\"\'\"'"}
- out_cmd_check=$(echo $file_loc | grep -Ei '.pdf')
- if [[ -n $out_cmd_check ]]; then
- pdf_cmd=$(echo exec wine "$pdfxchange_run_loc" "z:/$file_loc")
- if [ -f "$pdfxchange_run_loc" ]; then
- echo "skipping" > /dev/null
- else
- echo "copying"
- cp -r "$pdfxchange_dir_loc" "$ramdisk_loc"
- fi
- cmd=$(echo "lxterminal -e 'bash -c "'"'"$pdf_cmd"'"'"'")
- bash -c "$cmd" 2>/dev/null &
- win_title="PDF-XChange Editor"
- wait_for_window_to_activate "$win_title"
- sleep 1
- xdotool getwindowfocus windowmove 0 35
- xdotool getactivewindow windowsize 1814 1040
- else
- cmd=$(echo "lxterminal -e 'bash -c "'"ebook-viewer '"$file_loc"'"'"'")
- bash -c "$cmd" 2>/dev/null &
- win_title="E-book viewer"
- wait_for_window_to_activate "$win_title"
- sleep 1
- xdotool getwindowfocus windowmove 0 64
- xdotool getactivewindow windowsize 1814 1013
- fi
- fi
- }
- # main exec code:
- if echo $(xdotool getwindowfocus getwindowname) | grep -q "Archivarius 3000" ; then
- open_ebook
- elif echo $(xdotool getwindowfocus getwindowname) | grep -q "Dissenter" ; then
- tranquility_save
- fi
- # prameters of interest:
- # pdfxchange_dir_loc=$(echo ~/progs/pdfxchange)
- # pdfxchange_run_loc="/media/ramdisk/pdfxchange/PDFXEdit.x64.exe"
- # /media/ramdisk/recordings
- # /media/ramdisk
Add Comment
Please, Sign In to add comment