Capture double click event in of the current window? - linux

I'd like to know whether a user performed a double click in a certain application (specifically, evince). I wrote some code to check if evince is running and then whether it is focused application. However, I do not know how to check whether double-click was performed.
pids=$(xdotool search --class "evince")
curr_id=$(xdotool getwindowfocus)
if echo ${pids[#]} | grep -q -w $curr_id; then
echo "is in array"
else
echo "is not in array"
fi
I am a Java developer but I'm ready to do the coding in bash or Python.

Related

Collect input with Linux Dialogs

I found out about Dialogs, so I'm updating menus today. So far, so good.
I came to one where I need to collect a user's input.
I have
dialog --title " INPUT FILE NAME: " --inputbox "$(ls)" 30 40 2> answer
This will send the users input to a file named "answer"
I have tried
dialog --title " INPUT FILE NAME: " --inputbox "$(ls)" 30 40 2> $answer
but that doesnt seem to do anything.
I tried
answer=$(dialog --title " INPUT FILE NAME: " --inputbox "$(ls)" 30 40 2)
but there is some kind of error.
The manual page (for dialog) tells the story:
Some widgets, e.g., checklist, will write text to dialog's output.
Normally that is the standard error, but there are options for changing
this: "--output-fd", "--stderr" and "--stdout". No text is written if
the Cancel button (or ESC) is pressed; dialog exits immediately in that.
The reason dialog uses the standard error by default for its output is that it uses the curses/ncurses library, which normally prints its output (for the screen updates) to the standard output. To change dialog's behavior (and write to the standard output), use the "--stdout" option.
Interestingly (though it may appear an obvious problem to solve because it complicates scripting), the Xdialog program implemented this option first; it seemed a Good Thing to add to dialog (see changelog).
Done
dialog --title " INPUT FILE NAME: " --inputbox "$(ls )" 30 40 2>answer
ans=$(cat answer)
rm answer

how to get terminal properties

I very frequently work on multiple items in parallel and end up running some long tests or regression after working on something. I usually add a mail -s "foo" id < /dev/null at the end to know when a task ends so that I don't have to baby sit a long test or regression.
I was trying to automate this, where in I don't have to type the mail every time, just call a script (alias this to fewer characters - optimizing on how much I type) and the script figures out the test/regression from the cwd and sends an email. I thought it would be useful to send the terminal title or the screen session name in the email. Is there a way I can extract the terminal title or Linux screen window name?
You can find the screen session name, when attached, in $STY (the window number is available in $WINDOW if you need it):
$ echo "$STY"
6367.sessionname
You can find the uniquely identifying tty/pty device with tty:
$ tty
/dev/pts/34
Titles and such are features of xterm and not of the terminal itself, so terminals programs have a hard time deducing it.
Here's an example using both of the above to show the screen name if any, or the tty device otherwise:
mail -s "${STY:-$(tty)} done" < /dev/null
Screen also has a "wait for silence" feature where you can get a notification when processes in other screen windows have stopped outputting.

Linux dialog user input directly to variable

I am building a interactive bash script and I have been using whiptail for input and message boxes. However the infoboxes will not always work. (Works on my active server but not on my VM. Same Ubuntu 14.04 accessed with Putty in windows)
I am trying to switch to dialog but the code I was using with whiptail to output to a variable rather than a file does not seem to work in dialog.
UNAME=$(whiptail--inputbox "Enter the user you want your scripts to run as. (Case sensitive, Must exist)" 10 50 --title "System Username" 3>&1 1>&2 2>&3)
I tried changing whiptail to dialog and I get a box and can enter and submit data but then the variable is not set. I got this from another forum and there was no real description of whats actually happening here. All I know is it sets the variable with the input data rather than what is normally output to stderr.
dialog appears to be sensitive to option ordering. Put the --title option before the --inputbox option and it should work (at least it does here).

Simulating Enter in Bash Script on CentOS 6 Minimal

Right now I am using:
echo -ne '\n' | alternatives --config java
For
Enter to keep the current selection, or type selection number:
I know there are probably many ways to do this. I am looking for the correct way to perform this action. I honestly don't even know if I'm doing it right.
Probably you could use something less interactive.
alternatives --set java /your/favorite/version
should work.
Or you can use 'expect' command to emulate user input.

Menu Driven Shell Script bash

As a complete novice to this i am trying to make a Shell Script. This will be driven by a menu with options such as delete file. The part i am scuppered by is for example, when the menu is up, how to get from pressing '1', to actually creating a new file (as this is option 1 on my menu) I appreciate this may not be the easiest of questions to understand as my use of technical terms is limited, however i would appreciate any help. Below is an example of the first section of my menu. I feel once i know where to start i'll be fine
Menu
[1] Create File
[2] Delete File
[3] Rename file
Try doing this for example :
select x in "Create File" "Delete File" "Rename file"; do
echo "$x choosen"
break
done
Sample output
1) Create File
2) Delete File
3) Rename file
>
Search select in the conditional construct paragraph here
Going further
To run some specific tasks with the result of the $x variable, you can use the case statement (like switch in other languages) like this :
case $x in
Create*) touch file.txt ;;
Delete*) rm -f file.txt ;;
Rename*) mv file.txt file_old.txt ;;
esac
You can do it using switch/case statement. Please have a look on the bash manual or look for similar examples on the Web. Just google "switch case shell example"
Good luck

Resources