Two fast clicks, Close Shortcut Algorithm

If it doesn't relate to Debian, but you still want to share it, please do it here

Two fast clicks, Close Shortcut Algorithm

Postby bester69 » 2019-01-15 02:35

Hi,

I would like a script "closeall/killall this_App" when clicking two quick times in the shortcut application. Do you happen to know about some good code or a properly way to implement this?

Ive done this script to close all dolphin opened instances when clicking fast two followed times (time lower than 200 msg is ok) , and seems to work ok, thought I feel Its giving some overhead or retard when launching dolphin with it.


- Clicking One time >> Open dolphin explorer
- Clicking Two fast followed times >> Close All dolphin instances.


dolphin_closeall.sh
Code: Select all
#!/bin/bash
#
compsg=180
A=0
B=0

cat .flag2   && rm .flag .flag2
cat .flag  && A=1

dolphin &

 if [ $A -eq  1  ]
 then
 timepass=$(echo $(($(date +%s%N)/1000000)))
 time1=$(cat .flag)
 milisg=$(( $timepass - $time1 ))
 echo "timepass=$timepass - time1=$time1 = $milisg"
 
  if [ $milisg -ge  $compsg  ]
 then   
echo ">1 sg, excede el tiempo: $milisg"
 A=0
 rm .flag
 fi

 fi


echo "A es igual =$A"
 if [ $A -eq  0  ]
 then
 
 time1=$(echo $(($(date +%s%N)/1000000)))
 echo $time1 > .flag
 echo "Flag = $time1"
 else
 time2=$(echo $(($(date +%s%N)/1000000)))
 echo $time2 > .flag2
 echo "Flag2 = $time2"
 B=1
       fi

 if [ $B -eq  1  ]
 then       
time2=$(cat .flag2)
time1=$(cat .flag)
milisg=$(( $time2 - $time1 ))
echo "time2=$time2 - time1=$time1 = $milisg"


if [ $milisg -lt  $compsg  ]
 then       
 echo "timediff es menor que 1sg: $compsg"
 killall dolphin
 fi
 
fi

bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1413
Joined: 2015-04-02 13:15

Re: Two fast clicks, Close Shortcut Algorithm

Postby bw123 » 2019-01-15 20:31

It's pretty interesting. I don't think it will be consistent because the amount of time it takes to launch bash, open dolphin & then record the time will not be predictable enough to make it reliable. System load and other things like disk access might throw it off? Also, it will close all dolphin instances? Not just ones you launch with single click on this script?

If I was going to try it, I'd use dash, and record/compare the time as the first commands in the script.

There's probably a way to get X to detect and report a dbl click, have you searched the repo for some older cli X apps? I know there's one that detects idle, but I can't remember the tool. Try that direction maybe?

good luck
User avatar
bw123
 
Posts: 3787
Joined: 2011-05-09 06:02

Re: Two fast clicks, Close Shortcut Algorithm

Postby Head_on_a_Stick » 2019-01-15 20:51

bw123 wrote:If I was going to try it, I'd use dash

^ This.
Code: Select all
#!/bin/sh

There are no bashisms in the script so why slow it down?
User avatar
Head_on_a_Stick
 
Posts: 10321
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Two fast clicks, Close Shortcut Algorithm

Postby bw123 » 2019-01-15 22:01

I found this interesting instead of using date command and semaphore files, might knock off a little to use a var and store in tmp somewhere?

re: bash

Code: Select all
$ printf -v TIMESTAMP '%(%s)T' -1
$ echo $TIMESTAMP
1547590428
$ bash --version
bash --version
GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
User avatar
bw123
 
Posts: 3787
Joined: 2011-05-09 06:02

Re: Two fast clicks, Close Shortcut Algorithm

Postby bester69 » 2019-01-15 22:50

bw123 wrote:It's pretty interesting. I don't think it will be consistent because the amount of time it takes to launch bash, open dolphin & then record the time will not be predictable enough to make it reliable. System load and other things like disk access might throw it off? Also, it will close all dolphin instances? Not just ones you launch with single click on this script?

If I was going to try it, I'd use dash, and record/compare the time as the first commands in the script.

There's probably a way to get X to detect and report a dbl click, have you searched the repo for some older cli X apps? I know there's one that detects idle, but I can't remember the tool. Try that direction maybe?

good luck


You can use it, Its working very, very well, you can check it (it doesnt need any tweaking).. At first I thought there was some kind of lagging, but It was feeling biasing. I calibrated time clicking gap to 200mseg; lower than that, you can'r trigger double click with your hand, bigger than that, you have the risk to close all instances if you open very followed several instances.. Im king of glad with this code of my own, You can also use it for konsoles same code (very usefull). I use instead one single click closeall script for konsoles.

It took me several hours make it work, Im not a developer so... :?
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1413
Joined: 2015-04-02 13:15

Re: Two fast clicks, Close Shortcut Algorithm

Postby bw123 » 2019-01-15 23:08

That's great, thanks for sharing the script. I'm more of a "one fm" kind of guy. I only use midnight commander in one instance to manage files on the system. Dolphin is just too damn slow and GUIey, as every X app is. I can't imagine why I would need more than one fm open? But I will test it out, cuz I love scripts.
User avatar
bw123
 
Posts: 3787
Joined: 2011-05-09 06:02

Re: Two fast clicks, Close Shortcut Algorithm

Postby bester69 » 2019-01-15 23:38

bw123 wrote:That's great, thanks for sharing the script. I'm more of a "one fm" kind of guy. I only use midnight commander in one instance to manage files on the system. Dolphin is just too damn slow and GUIey, as every X app is. I can't imagine why I would need more than one fm open? But I will test it out, cuz I love scripts.

hehehe I also enjoy making scripts, but Im very bad at that. :) Ive just seen How many script Ive done and keep, and they're around 360..I think Ive installed aroun 100 or so, many of them I dont remember for what purpose I make them. Ive a script foder where I drop every script I develop and find usefull to keep. fortunately I can find anything in my home folder thanks to recoll-index.
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1413
Joined: 2015-04-02 13:15

Re: Two fast clicks, Close Shortcut Algorithm

Postby xepan » 2019-01-16 07:48

if you use bash, use [[, not [.
if you use [, use quotes.
and don't use uppercase variables in your scripts.
don't use cat to get content of files, but "read".

minor? of course.
xepan
 
Posts: 89
Joined: 2018-11-28 06:38


Return to Offtopic

Who is online

Users browsing this forum: No registered users and 11 guests

fashionable