14

I found it not that efficient to move the mouse pointer over the notification and click on the reply button every time.

So I was wondering if there is a hotkey for quick reply instead of using the mouse or the trackpad.

1

You could assign a keyboard shortcut to a script like this:

tell application "System Events" to click window 1 of process "Notification Center"
  • 1
    I've tried that using Keyboard Maestro. But it simply brings up the Message window to the front, rather than doing a quick reply after clicking on the reply button. Is there any script that can click on that button? Thanks! – ylorn Nov 14 '13 at 15:31
  • And also, I've tried something like tell application "System Events" to click button "Reply" of window 1 of process "Notification Center" But it does not work. Because you have to move the mouse pointer over the notification, or the reply button won't appear. – ylorn Nov 14 '13 at 15:34
  • @ylorn I don't use Messages, but I thought clicking a notification would reply to the message. click button "Reply" of window 1 might work if you changed the alert style from banners to alerts. – Lri Nov 14 '13 at 21:57
0

Here's a script to do this using Yosemite's JavaScript for Automation and its Objective-C bridge.

ObjC.import("CoreGraphics");
// Notification only detects hover when moving from outside its borders
// over it, so first go to (0, 0).
$.CGWarpMouseCursorPosition({x:0 , y:0});
mainDisplayWidth = $.CGDisplayPixelsWide($.CGMainDisplayID());
$.CGWarpMouseCursorPosition({x:mainDisplayWidth - 50, y:81});

Application("System Events")
    .processes["Notification Center"]
    .windows()[0]
    .buttons["Reply"]
    .click();

If you want to run this in a shell (e.g. Alfred doesn't support JavaScript yet), you can use this one-liner that executes the script via osascript:

echo 'ObjC.import("CoreGraphics"); $.CGWarpMouseCursorPosition({x:0 , y:0}); mainDisplayWidth = $.CGDisplayPixelsWide($.CGMainDisplayID()); $.CGWarpMouseCursorPosition({x:mainDisplayWidth - 50, y:81}); Application("System Events") .processes["Notification Center"] .windows()[0] .buttons["Reply"] .click(); ' | osascript -l JavaScript

You can assign this script to a shortcut using any automation tool. I'm using Alfred, FastScripts works as well.

You'll have to allow the automation tool you're using to control your Mac, otherwise the mouse will move, but the script can't click the 'Reply'. In my case, I added Alfred there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .