Hi,
I'd love to have a way to put the cursor on an open app in the dock, make a gesture on the trackpad, and close it (instead of, right click it > quit application; or click on the app and then CMD + Q).
I'm sure many other people find this tedious!
I'd love to have reccomandations for this. thanks!
there are a couple ways i use:1) using applescript 2) javasctipt and then with help from posterr here with give them shoutout when i edit this as i am pressed for time at moment and will post my other way
(async()=>{
AS=s=>runAppleScript(s)
BP=s=>runShellScript({script:`afplay /System/Library/Sounds/Tink.aiff -v 0.3 >/dev/null &`})
NT=async(c)=>{
let n='eDockHUD'+(!c?'S':'')
await set_string_variable({variable_name:n,to:!c?"asterisk.circle":c})
trigger_named(n)
}
A=await get_string_variable("hovered_element_details")
V=i=>A.split('AX'+i+': "')[1].split('"')[0]
F=V('Subrole').slice(2,4)
setTimeout(e=>NT(),150)
if(F=="Ap"&&(V('IsApplicationRunning')*1)){
N=V('Title')
if(N=="BetterTouchTool"){
AS(`
tell app "System Events" to tell windows of process "`+N+`"
click (buttons whose subrole is "AXCloseButton")
if count>0 then
tell app "`+N+`" to activate
delay 0.3
key code 53
click (buttons whose subrole is "AXCloseButton")
end if
end tell
`)
}else if(N=="Finder"){
AS(`
quit app "Finder"
delay 0.2
launch app "Finder"
`)
}else{
AS(`quit app "`+(decodeURIComponent(V('URL')).slice(7,-1))+`"`)
}
BP()
}else if(F=="Mi"){
trigger_action({json:{BTTPredefinedActionType:3}})
AS(`delay .3
tell app "System Events" to tell window 1 of process (short name of (info for (path to "egfp"))) to click (buttons whose subrole is "AXCloseButton")`)
BP()
}else if(F=="Se"){
NT("DM"+await AS(`tell app "System Events" to tell dock preferences to set {magnification} to {not magnification}`))
}else if(F=="Tr"){
R=1
setTimeout(e=>R*1?BP():NT("T"),100)
R=await AS(`tell app "Finder" to empty trash
1`)
}else{
AS(`beep`)
}
returnToBTT(1)
})()
create a new trackpad gesture i use 3 finger tap, and then select Run Real Javasscript as action and paste code above in code area and also select option 'only when hovered over doc'k' ---menu on bottom part when click a triggers advaned option-thiss way only enables code when hovered over dock
here is another way real quick this one has a confirm quit dialog
new trackpad gesture
add action "acctivate currenly hovered app in dock"
add another new action should be listted after one above----select add Run Applescript
paste the applescrpit. code below
try
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
display dialog "Quit?"
end tell
tell application frontApp to quit
on error errMsg
display dialog "Error: " & errMsg buttons {"OK"} default button "OK" with icon stop
end try
try
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
display dialog "Quit?"
end tell
tell application frontApp to quit
on error errMsg
display dialog "Error: " & errMsg buttons {"OK"} default button "OK" with icon stop
end try
try
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
display dialog "Quit?"
end tell
tell application frontApp to quit
on error errMsg
display dialog "Error: " & errMsg buttons {"OK"} default button "OK" with icon stop
end try
try
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
display dialog "Quit?"
end tell
tell application frontApp to quit
on error errMsg
display dialog "Error: " & errMsg buttons {"OK"} default button "OK" with icon stop
end try
Just another applescipt to try see what works best for you thiis has dialog but easy remove
try
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
display dialog "Quit?"
end tell
tell application frontApp to quit
on error errMsg
display dialog "Error: " & errMsg buttons {"OK"} default button "OK" with icon stop
end try
try
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
display dialog "Quit?"
end tell
tell application frontApp to quit
on error errMsg
display dialog "Error: " & errMsg buttons {"OK"} default button "OK" with icon stop
end try
Dude you are a legend.
However I’m a legendary noob compared to you.
May I kindly ask you to let me know a very easy step by step for how to do it and how to manage it.
Like 1) open terminal
2) past message number x
3 to modify / cancel this feature, go to x and do y.
If you can’t no worries, thanks either way for the time, I really appreciate it!
here yet another way using some simple applescript to close hovered app in dock. Ill add instructions and couple screenshots. LMK if stlll need help getting it working.
Here is the last applescript version you can use, it has no dialog nor any beeps on fail etc just simple and plain-when activated quits app mouse is. hovering in dock
use application "System Events"
property Dock : me
property process : application process "Dock"
property list : a reference to list 1 of my process
property item : a reference to (UI element 1 in my list whose selected = true)
--------------------------------------------------------------------------------
# IMPLEMENTATION:
if the Dock's item exists then tell the selectedItem ¬
to if its attribute exists then ¬
if its running then quit it
--------------------------------------------------------------------------------
# HANDLERS & SCRIPT OBJECTS:
script selectedItem
property name : a reference to title of my item
property AX : "AXIsApplicationRunning"
property attribute : a reference to attribute AX of my item
property running : a reference to the value of my attribute
property application : a reference to the application name
to activate
activate my application
end activate
to quit
quit my application
end quit
end script
---------------------------------------------------------------------------❮END❯
Open BetterTouchTool (BTT)
Make sure you have BTT installed and running on your Mac.
Choose Your Trigger
Select Your Device:In BTT, navigate to the configuration for your specific input device (e.g., Trackpad, Magic Mouse)
Add a Gesture: Click "Add a New Gesture" and choose the trackpad gesture you want to use (e.g., Three Finger Swipe Up, Four Finger Tap).
Configure the Action
In the "Trigger Predefined Action" section, select "Run Apple Script (blocking)".
Paste Your Code: Paste your AppleScript code into the provided text area.
Make it so only executes when over dock and doesnt affect if. you want to use same gesture again just not over dock. So select Only. When Hovered Over Dock--notice it iis in the advanced tab
Try It Out:Perform your trackpad gesture to see if the AppleScript executes correctly.
Example
Let's say you want to create a Three Finger Swipe Down gesture to hide all applications except the frontmost one. Here's the AppleScript code and how you'd add it to BTT:
tell application "System Events"
tell process "Finder" to set visible of every process whose frontmost is false to false
end tell
or in our case replace the above code with any of the ones provided
Sorry for the late reply, it took me some courage to try out, I got scarred from all the coding... but I'm glad to report from duty:@wynstaxxx you're the man, the myth, the legend - it worked! I finally have this! thank you so. much. for the unreal effort you put into this, I very much appreciate it! I can finally do this thing I wanted to do for ages! 10 open applications that are cluttering my dock - begone.
I wish you all the best dude! And I hope other people will use this thing, as honestly I find it very useful!
thanks! glad its working for to you and was able to help you and hopefully any others.
Just wanted to add you can create a variety of features setup to activate other actions besides just the QUIT action, like in this example. I setup a bunch of trackpad gestures over the dock to trigger actions such as minimize window, full-screen, hide other apps, create a new window ie. double 1 click for new fnder window (can setup for a specific or as many apps as you like it to work on) .....also unminimize window scripts, force quit, add dialogs to actions to confirm etc etc.
Just some ideas let me know if you need any help again etc and best of luck and enjoy
Damn that sounds interesting, thought I think for now my adventure outside my comfort zone of BTT has been more than enough for me. I'll definitely keep this in mind then,
Thanks again and all the best :)!