不用鼠标关闭 iCal 闹钟?

不用鼠标关闭 iCal 闹钟?

现在 Snow Leopard 已经推出,我已经停止使用 Entourage(哇哦!)并且现在使用 iCal。

有没有办法不用鼠标来关闭 iCal 闹钟(例如“上午 11:00 的会议在 10 分钟后开始”)?

我无法-Tab转到窗口。如果我切换到 iCal,闹钟窗口就不会处于焦点。我也无法-`转到那个窗口。

答案1

在 AppleScript 编辑器中,创建以下脚本:

tell application "iCal Helper" to quit
delay 2
tell application "iCal Helper" to launch

使用 Quicksilver、Butler、FastScripts(lite)、Controllermate 等应用程序创建操作/快捷方式来启动脚本。

我重新启动该应用程序的原因是我们希望它在后台打开以接收下一个事件/消息。

答案2

您可以使用 applescript。这将使 iCal 闹钟处于活动状态:

tell application "iCal Helper"
 activate
end tell

您可以使用 FastScripts、QuickSilver、LaunchBar 或您选择的键盘快捷键应用程序来启动脚本,然后您可以键入 escape 来关闭它。

我不认为 iCal Helper 应用程序可以编写脚本,因为我无法通过鼠标坐标将 Esc 键或鼠标单击传递给它。不过,您可以为脚本提供一个快捷方式,如 Option-Esc,然后手动执行另一个 Esc 来关闭它。

我无法让它在 10.5.8 上运行,但也许 iCal Helper 在 10.6 中更具脚本化?

tell application "iCal Helper"
 activate
 click at {1062, 300}
end tell

我通过键入 Command Shift 4 来获取坐标,因为屏幕截图应用程序会提供坐标。警报很方便地显示在同一位置,但您的显示器分辨率会导致您的坐标与我的不同。如果有人比我更了解 AppleScript,我很好奇为什么上面的“单击”行不起作用。

答案3

成立

但当然,如果你点击“x”按钮,Mac OS X 实际上会将 iCal 带到前台,无论你是否喜欢。换句话说,如果不切换到 iCal,就无法关闭 iCal 闹钟。这真是……令人恼火。

答案4

这里的其他答案都不适合我。我使用下面的代码(发现这里) 并且它在OSX Yosemite (10.10.2) 上运行完美。

我还对代码进行了一些调整,使其可以作为 Alfred v2 工作流运行,然后发布了它在 GitHub 上

on run
    closeNotifications()
end run

on closeNotifications()
    try
        -- This function closes all currently displaying notification alerts. It used to also return the titles of each notification, which I have commented out to disable.
        tell application "System Events"
            tell process "Notification Center"
                set theseWindows to every window whose subrole is "AXNotificationCenterAlert" or subrole is "AXNotificationCenterBanner"
                --set theseTitles to {}
                repeat with thisWindow in theseWindows
                    try
                        -- Save the title of each alert window:
                        --set thisTitle to the value of static text 1 of scroll area 1 of thisWindow
                        --set the end of theseTitles to thisTitle

                        -- Close each alert:
                        click button "Close" of thisWindow
                    end try
                end repeat --"theseWindows"
                --return theseTitles
            end tell -- "NotCenter"
        end tell -- "SysEvents"

    on error errorMessage number errorNumber
        if errorNumber is errorNumber then
            my addAppletToAccessibilityList()
            error number -128
        end if
    end try
end closeNotifications

on addAppletToAccessibilityList()
    -- This function gets the user to enable Accessibility, for scripting the UI interface (hitting buttons etc.)
    set thisAppletFile to (path to me)
    tell application "Finder" to reveal thisAppletFile
    tell application "System Preferences"
        launch
        activate

        reveal anchor "Privacy_Assistive" of pane id "com.apple.preference.security"

        activate

        display alert ¬
            "Add Applet to Accessibility" message "In order to respond to user clicks on Notification panels and alerts, this applet must be added to the lost of apps approved to use accessibility controls of the OS." & return & return & ¬
            "To add this app:" & return & return & ¬
            "1) Click the lock icon (if it is locked) and enter your password." & return & return & ¬
            "2) If 'SystemUIServer.app' is in the list, check the box next to it's name." & return & return & ¬
            "Otherwise, if the applet's name is in the list, check the box next to it's name. If it's not in the list, drag the applet (currently shown in the Finder) into the list area." & return & return & ¬
            "3) Click the lock to re-lock the preference pane, close System Preferences."
    end tell
end addAppletToAccessibilityList

相关内容