Advertisement
Guest User

archivarius 3000 Linux wine internal association

a guest
Apr 27th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.49 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function wait_for_window_to_activate() {
  4.   # first parameter  - window title or part of the window title
  5.   window_title="$1"
  6.   time_sec=900
  7.   while [[ 0 -ne $time_sec ]]; do
  8.     echo "$time_sec, waiting... to activate"
  9.     time_sec=$[$time_sec-1]
  10.     xdotool search --onlyvisible --name "$window_title" windowactivate
  11.     if [[ $? == 0 ]]; then
  12.       sleep 0.5
  13.       window_name=$(xdotool getwindowfocus getwindowname)
  14.       if echo $window_name | grep -q "$window_title" ; then
  15.         echo "window active "$window_name
  16.         break
  17.       fi
  18.     fi
  19.     sleep 0.5
  20.   done
  21. }
  22.  
  23. function repeat_send_key() {
  24.   window_title="$1"
  25.   key="$2"
  26.   repeat="${3:-1}"
  27.   xdotool search --onlyvisible --name "$window_title" windowactivate
  28.   if [[ $? == 0 ]]; then
  29.     for (( i=1; i <= repeat; i++ ))
  30.     do
  31.      xdotool key $key
  32.      sleep 0.1
  33.     done
  34.   fi
  35. }
  36.  
  37. function open_ebook() {
  38.   win_title="Archivarius 3000"
  39.   wait_for_window_to_activate "$win_title"
  40.   echo -n "" | xclip -selection clipboard
  41.   repeat_send_key "$win_title" "Shift+F10"
  42.   sleep 0.5
  43.   repeat_send_key "$win_title" "Up" 3
  44.   repeat_send_key "$win_title" "Right"
  45.   repeat_send_key "$win_title" "Down"
  46.   repeat_send_key "$win_title" "Return"
  47.   clip_read=$(xsel -b)
  48.   if [[ ! $clip_read == "" ]]; then
  49.     first_trim=${clip_read#*$'\n'}
  50.     result=$(echo $clip_read | grep -Ei '.epub')
  51.     if [[ -n $result ]]; then
  52.       echo "epub detected"
  53.       file_name=${first_trim##*"Z:"}
  54.       file_name=${file_name%".epub"*}".epub"
  55.       file_loc=${file_name//\\//}
  56.     else
  57.       echo "other formats"
  58.       file_name=${first_trim%"%"*}
  59.       file_name=$(echo "$file_name" | sed 's/[[:blank:]]/ /g' | awk '{$1=$1};1')
  60.       file_name=${file_name%" "*}
  61.       second_trim=${first_trim#*%}
  62.       sufix=${second_trim##*\\}
  63.       file_folder=${second_trim%"$sufix"*}
  64.       file_folder=${file_folder##*"Z:"}
  65.       file_folder=${file_folder//\\//}
  66.       file_loc=$file_folder$file_name
  67.     fi
  68.     escape=("[" "]" "~" "!" "{" "}" "(" ")" "$" "@" "<" ">" ":" ";" "," '`' "%" "+" "=" '"' "|" "?" '*' "&" " " "'")
  69.     for e in "${escape[@]}"
  70.     do
  71.       file_loc=${file_loc//[$e]/\\$e}
  72.     done
  73.     file_loc=${file_loc//"\\'"/"'\"\'\"'"}
  74.     out_cmd_check=$(echo $file_loc | grep -Ei '.pdf')
  75.     if [[ -n $out_cmd_check ]]; then
  76.       pdfxchange_dir_loc=$(echo ~/progs/pdfxchange)
  77.       pdfxchange_run_loc="/media/ramdisk/pdfxchange/PDFXEdit.x64.exe"
  78.       pdf_cmd=$(echo exec wine "$pdfxchange_run_loc" "z:/$file_loc")
  79.       if [ -f "$pdfxchange_run_loc" ]; then
  80.         echo "skipping" > /dev/null
  81.       else
  82.         echo "copying"
  83.         cp -r "$pdfxchange_dir_loc" "/media/ramdisk"
  84.       fi
  85.       cmd=$(echo "lxterminal -e 'bash -c "'"'"$pdf_cmd"'"'"'")
  86.       bash -c "$cmd" 2>/dev/null &
  87.       win_title="PDF-XChange Editor"
  88.       wait_for_window_to_activate "$win_title"
  89.       sleep 1
  90.       xdotool getwindowfocus windowmove 0 35
  91.       xdotool getactivewindow windowsize 1814 1040
  92.     else
  93.       cmd=$(echo "lxterminal -e 'bash -c "'"ebook-viewer '"$file_loc"'"'"'")
  94.       bash -c "$cmd" 2>/dev/null &
  95.       win_title="E-book viewer"
  96.       wait_for_window_to_activate "$win_title"
  97.       sleep 1
  98.       xdotool getwindowfocus windowmove 0 64
  99.       xdotool getactivewindow windowsize 1814 1013
  100.     fi
  101.   fi
  102. }
  103.  
  104. if echo $(xdotool getwindowfocus getwindowname) | grep -q "Archivarius 3000" ; then
  105.   open_ebook
  106. elif echo $(xdotool getwindowfocus getwindowname) | grep -q "Dissenter" ; then
  107.   echo "do something else"
  108. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement