Advertisement
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 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 open_ebook() {
- 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
- pdfxchange_dir_loc=$(echo ~/progs/pdfxchange)
- pdfxchange_run_loc="/media/ramdisk/pdfxchange/PDFXEdit.x64.exe"
- 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" "/media/ramdisk"
- 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
- }
- if echo $(xdotool getwindowfocus getwindowname) | grep -q "Archivarius 3000" ; then
- open_ebook
- elif echo $(xdotool getwindowfocus getwindowname) | grep -q "Dissenter" ; then
- echo "do something else"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement