Jump to content

Assigning ⌘Q In the Hotkey Object


Recommended Posts

Can I assign ⌘Q as a hotkey for a specific app? 

 

image.thumb.png.bbef9b8969b54598ff39741124fca272.png

 

The Object won't respond to ⌘Q so I tried to edit the plist file directly. It looked like the ⌘Q hotkey is set.

image.thumb.png.ee0c4d10d5fe105d970e4fc8647701f3.png

 

But Alfred didn't seem to be able to handle it, even if I manually change the default hotkey setting for the action to something other that ⌘Q in System Settings:

 

image.thumb.png.09face9b210f104e3e5aafdf446042fa.png

 

What I want to do is assigning ⌘Q to an AppleScript so I can see how many windows and tabs I have opened in Safari and have a on-quit warning:
 

tell application "Safari"
	set _window_count to count windows
	set _tab_count to 0
	
	repeat with _w in every window
		set _tab_count to _tab_count + (count tabs of _w)
	end repeat
	
	-- Make a string like "1 window containing 3 tabs."
	if _window_count is 1 then
		set _msg to _window_count & " window containing " as string
	else
		set _msg to _window_count & " windows containing " as string
	end if
	if _tab_count is 1 then
		set _msg to _msg & _tab_count & " tab." as string
	else
		set _msg to _msg & _tab_count & " tabs." as string
	end if
	
	display alert ¬
		"Are you sure you want to quit Safari?" message _msg ¬
		buttons {"Cancel", "Quit"} ¬
		giving up after 60
	if button returned of result is "Quit" then quit
end tell

 

I'm currently doing this using FastScripts, which has no problem of handling the ⌘Q hotkey despite the default macOS hotkey setting. I'm thinking of replacing the whole app with Alfred, but now it seems that Alfred does not handle hotkeys like ⌘Q by design? 

 

Any help will be appreciated! 

 

Link to comment

Editing the plist should indeed work, I have just tested. Make sure that section looks like this:

 

<key>hotkey</key>
<integer>12</integer>
<key>hotmod</key>
<integer>1048576</integer>
<key>hotstring</key>
<string>Q</string>

 

Or try this quick example.

 

Naturally, all the caveats apply that replacing ⌘Q could lead to undesirable results as far as macOS is concerned, so be careful with that.

Link to comment

Hi,  @vitor !

 

Thank you for the snippet and the example, they both worked for me too👍️ I can uninstall FastScript now. 🤠

 

I tried setting the hotkey to handle ⌘E in Alfred Preferences and edited the hotstring part to Q in the plist. So my edited plist looked like this (it didn't work):

<key>hotkey</key>
<integer>14</integer>
<key>hotmod</key>
<integer>1048576</integer>
<key>hotstring</key>
<string>Q</string>

I thought that 14 must stand for ⌘, but that doesn't always seem to be the case. 🤔 And I noticed if I set the hotkey to ⌘2, it says 19 instead. I wonder what hotkey gave you the 12 value. 

Link to comment
14 hours ago, vitor said:

Naturally, all the caveats apply that replacing ⌘Q could lead to undesirable results as far as macOS is concerned, so be careful with that.

As for the risk, I'll reply here if I happen to experience any issue. But so far so good, ⌘Q is working as I wished for both the target app (Safari) and other apps. Thanks for the heads-up!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...