Accidental Command + Q prevention

Hi.
Is there a way I can add something that, when I press command + q to shut a tab, a dialog box appears with the title: 'Warning', and the text: 'Do you really want to quit?'. The default button will be 'Yes', which shuts it, and then there will obviously be a cancel button.
Thanks

bump...@Andreas_Hegenberg?

Apple Script. Make ⌘W display window with text, make it disappear after x seconds and then close the window- but if you interact with it, end the script.
You found in the other Thread how to make a dialog box appear, interaction examples can be found easily on google!

1 Like

okay. just to make sure ive done this right:

  • I made a top level new trigger under 'Keyboard Shortcuts'.

  • I used Command + Q as the shortcut.

  • I set it to trigger Apple Script (Blocking)

  • Put in this coding (copied from my battery dialog box testing):

      set theDialogText to "Do you really want to quit?"
    
      display dialog theDialogText buttons {"Yes"} default button "Yes" cancel button "Yes" giving up after 1000 with title "Warning"
    
      if gave up of result = true then
    
      tell application "System Events"
    
      start current screen saver
    
      end tell
    
      end if
    

Now, how do I add a 'cancel' button? And how do I make it actually quit the currently open app?
Thanks

update:
after research, I found that doing the code following code will quit a specific application
tell application "Calculator"

        quit

   end tell

I also read that apple script mainly takes specific apps to work

so would it work if it was set to a trigger UUID that used the shortcut 'command + q'?

I'm sorta going out on a limb here, as you know I have no previous knowledge of apple script
thanks

another update....

I found stuff and somehow put it together to make:
display dialog "Do you really want to quit?" buttons {"Cancel", "Yes"} default button 2 with icon caution

so now how do i make it so that if 'Yes' is pressed, the currently running app quits?
thanks

Add this at the end:

if the button returned of the result is "Yes" then
	tell application (path to frontmost application as text)
		quit
	end tell
else
	return "canceled"
end if

The whole script would look like that:

display dialog "Do you really want to quit?" buttons {"Crap, no", "Yes"} default button 2 with icon caution
if the button returned of the result is "Yes" then
	tell application (path to frontmost application as text)
		quit
	end tell
else
	return "canceled"
end if

(See that I took away you "with giving up after 1000" - 1000 is a ridiculously high value, I assumed you want the box to stay until you confirmed. You can achieve it this way. The giving up after is useful if you want to make the box disappear after a short period of time)
Also I made it work universally (with every application) using the path to frontmost application as text line - this quits the frontmost application.

1 Like

good news: it worked
bad news: it crashed btt and I lost absolutions;ty everything and now I have to start again....
@Andreas_Hegenberg

No backups?

You can try to restore one of the auto backups:

I was working on a new version for like 7 hours and then I restarted BTT because it froze and now everything's back....haha scared me shitless though. everything's fine now :slight_smile:

@Caliguvara i think needless to say, I won't be using your 'quitting' code (which is a shame, it would've been really helpful). I think that's what caused BTT to crash and restart.....maybe in a few weeks when I feeling for confident again, ill give it another try.
thanks

just export your preset as a backup before trying it again (you should do that anyways from time to time).

1 Like

yep. never thought of that lol. doing it now....

@Caliguvara i think i will use that, (after exporting my preset), but now it isn't working.. it only comes up with the dialog box after i bring BTT as the frontmost app otherwise it does the little 'error' ding sound that apple has.

and BTT crashed and it happened again.. screwed up touch bar. why is this happening @Andreas_Hegenberg? what do i need to do to stop it?

and ima try again now that my problem is solved (thanks Andreas)

@Caliguvara how can I fix this?

I can show a screen recording if you want

Close the BTT window.

thanks very much :slight_smile:

1 Like