Triggering events with multiple clicks (double clicks or as many as you like)

Ok so I know I am going a little over board .. but I took this idea form movingimage from the post found here and modified it to work with as many clicks as you would like.

It will execute a different trigger for each click as you go..

I have a screen setup that has 8 different snap areas and this allows me to rotate my active window through all of them by continuing to push the same button/keystroke. It does have a timeout of one second.. so if you can not click faster than one second per click you can adjust the time.

steps

  1. Add the desired triggers to the "Named and other Triggers" section of BTT

  2. Set up a Button/Keystroke and assign it to "Run Apple Script (async in background)" and copy the below script in

  3. adjust the script for how many clicks you would like in the clickCheck section. I put in ten but I only use eight. you just have to move the line indicated with a
    "-- Move me to the amount of clicks you have"

  4. Rename the trigger events to match the ones you set up on the "Named and other Triggers" page in step 1

  5. Click the "Complie / Test" button and then select save.

  6. Click/Push/Keystroke your key or button that you set up and watch the magic happen.

Note*** if you use this multiple times for other triggers you may want to change the global variables as they would conflict with the other.

--#########################################################################################################

--# Written by doctorquad July 2020

--# This script will do exactly what you tell it to ... The common problem in all errors is YOU

--# Author takes no responsibility to how when or where you use this script... Note the above comment.

--#########################################################################################################

global currentCount

global lastRunTime

--Set this to the time delay in secconds that you would like

checkDuration()

--################################

--Check to see if it has been more then 3 secconds

on checkDuration()

try

-- Set the duration based on the global variable that was set last time this ran so we know how long it has been.

set duration to ( current date ) - lastRunTime

-- If it has been less then the set timeDelay run the clickCheck. if not reset the count and run the clickCheck

--Set this to the time delay in secconds that you would like

if duration ≤ 1 then

--Run the clickCheck with the current count of clicks

clickCheck(currentCount)

else

--We missed the timedelay window so reset the count and run the clickCheck

resetCount()

clickCheck(currentCount)

end if

on error

-- If the script has not ran we get an error because the variables are not set.. we need to set the variables then run the clickCheck

set duration to "FirstAttempt"

resetCount()

clickCheck(currentCount)

end try

log "Duration from last click " & duration

end checkDuration

--################################

--################################

-- Update the last time this script was ran

on updateRunTime()

try

set lastRunTime to current date

end try

end updateRunTime

--################################

--################################

-- Reset the count to 0

on resetCount()

try

set currentCount to 0

end try

end resetCount

--################################

--################################

-- Incrament the count or set it to 0 in error

on increment()

try

log "incrementCount " & currentCount & "."

-- Increment the count by one

set currentCount to currentCount + 1

on error

set currentCount to 0

end try

end increment

--################################

--################################

--This is what does all the work depending on how many times you clicked will run through the clicks

on clickCheck(clicks)

try

log "clickCheck " & clicks

if (clicks = 0) then

tell application "BetterTouchTool"

--change this to be your 1st trigger name

trigger_named "MoveMain"

end tell

else if (clicks = 1) then

tell application "BetterTouchTool"

--change this to be your 2nd trigger name

trigger_named "MoveBigMain"

end tell

else if (clicks = 2) then

tell application "BetterTouchTool"

--change this to be your 3rd trigger name

trigger_named "MoveBottomLeft"

end tell

else if (clicks = 3) then

tell application "BetterTouchTool"

--change this to be your 4th trigger name

trigger_named "MoveTopLeft"

end tell

else if (clicks = 4) then

tell application "BetterTouchTool"

--change this to be your 5th trigger name

trigger_named "MoveTopMain"

end tell

else if (clicks = 5) then

tell application "BetterTouchTool"

--change this to be your 6th trigger name

trigger_named "MoveTopRight"

end tell

else if (clicks = 6) then

tell application "BetterTouchTool"

--change this to be your 7th trigger name

trigger_named "MoveBottomRight"

end tell

else if (clicks = 7) then

tell application "BetterTouchTool"

--change this to be your 8th trigger name

trigger_named "MoveMain"

--This is where you set the count back to 1 so that it will keep looping. If you do not have 8 triggers then move these lines to the last one of your set.

set currentCount to 0 -- Move me to the amount of clicks you have

end tell

else if (clicks = 8) then

tell application "BetterTouchTool"

--change this to be your 9th trigger name

trigger_named "tbd"

end tell

else if (clicks = 9) then

tell application "BetterTouchTool"

--change this to be your 10th trigger name

trigger_named "tbd"

end tell

else

tell application "BetterTouchTool"

--change this to be your what trigger you would like the defualt to be.. you will most likly never hit this but you never know.

trigger_named "MoveMain"

end tell

end if

on error

tell application "BetterTouchTool"

--This is just the trigger that you would like to run if for some reason you get an error .. usually when you run the script for the first time as it has not populated the varables yet.

trigger_named "MoveMain"

end tell

end try

--Update the last run variable so that the timeout start over.

updateRunTime()

--incrament the count so the next click will go to the next trigger.

increment()

end clickCheck

--################################


awesome! just a tip: you can indent the coding by highlighting it and pressing Command + Shift + C

Yeah I am trying to get the format of the script to look better on the forum I tried your suggestion but it still looks the same

Ok found the "blockquote" button and that seems to have worked .. thanks for the tip.

1 Like

Not working.
here's my script :face_with_raised_eyebrow:
I tried with only 2 clicks.

--#########################################################################################################
--# Written by doctorquad July 2020
--# This script will do exactly what you tell it to ... The common problem in all errors is YOU
--# Author takes no responsibility to how when or where you use this script... Note the above comment.
--#########################################################################################################
global currentCount
global lastRunTime
--Set this to the time delay in secconds that you would like
checkDuration()
--################################
--Check to see if it has been more then 3 secconds
on checkDuration()
try
-- Set the duration based on the global variable that was set last time this ran so we know how long it has been.
set duration to ( current date ) - lastRunTime
-- If it has been less then the set timeDelay run the clickCheck. if not reset the count and run the clickCheck
--Set this to the time delay in secconds that you would like
if duration ≤ 1 then
--Run the clickCheck with the current count of clicks
clickCheck(currentCount)
else
--We missed the timedelay window so reset the count and run the clickCheck
resetCount()
clickCheck(currentCount)
end if
on error
-- If the script has not ran we get an error because the variables are not set.. we need to set the variables then run the clickCheck
set duration to "FirstAttempt"
resetCount()
clickCheck(currentCount)
end try
log "Duration from last click " & duration
end checkDuration
--################################
--################################
-- Update the last time this script was ran
on updateRunTime()
try
set lastRunTime to current date
end try
end updateRunTime
--################################
--################################
-- Reset the count to 0
on resetCount()
try
set currentCount to 0
end try
end resetCount
--################################
--################################
-- Incrament the count or set it to 0 in error
on increment()
try
log "incrementCount " & currentCount & "."
-- Increment the count by one
set currentCount to currentCount + 1
on error
set currentCount to 0
end try
end increment
--################################
--################################
--This is what does all the work depending on how many times you clicked will run through the clicks
on clickCheck(clicks)
try
log "clickCheck " & clicks
if (clicks = 0) then
tell application "BetterTouchTool"
--change this to be your 1st trigger name
trigger_named “split”
end tell
else if (clicks = 1) then
tell application "BetterTouchTool"
--change this to be your 2nd trigger name
trigger_named “esc”
end tell
else
tell application "BetterTouchTool"
--change this to be your what trigger you would like the defualt to be.. you will most likly never hit this but you never know.
trigger_named “split”
end tell
end if
on error
tell application "BetterTouchTool"
--This is just the trigger that you would like to run if for some reason you get an error .. usually when you run the script for the first time as it has not populated the varables yet.
trigger_named “split”
end tell
end try
--Update the last run variable so that the timeout start over.
updateRunTime()
--incrament the count so the next click will go to the next trigger.
increment()
end clickCheck
--################################

Imprint | Privacy Policy