Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Two fast clicks, Close Shortcut Algorithm

Off-Topic discussions about science, technology, and non Debian specific topics.
Post Reply
Message
Author
User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Two fast clicks, Close Shortcut Algorithm

#1 Post by bester69 »

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:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Two fast clicks, Close Shortcut Algorithm

#2 Post by bw123 »

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
resigned by AI ChatGPT

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Two fast clicks, Close Shortcut Algorithm

#3 Post by Head_on_a_Stick »

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?
deadbang

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Two fast clicks, Close Shortcut Algorithm

#4 Post by bw123 »

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)
resigned by AI ChatGPT

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: Two fast clicks, Close Shortcut Algorithm

#5 Post by bester69 »

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:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Two fast clicks, Close Shortcut Algorithm

#6 Post by bw123 »

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.
resigned by AI ChatGPT

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: Two fast clicks, Close Shortcut Algorithm

#7 Post by bester69 »

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:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

xepan
Posts: 89
Joined: 2018-11-28 06:38

Re: Two fast clicks, Close Shortcut Algorithm

#8 Post by xepan »

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.

Post Reply