Applescript:切换Alfred

Applescript:切换Alfred,applescript,Applescript,我试图通过写一些Applescript让Alfred通过键盘大师来切换。这是我现在正在使用的代码,但不用于停用Alfred窗口,因为它看起来像Alfred没有作为窗口激活 set appName to "Alfred 3" set is_start to false tell application "System Events" if not (exists process appName) then set is_start to true else

我试图通过写一些Applescript让Alfred通过键盘大师来切换。这是我现在正在使用的代码,但不用于停用Alfred窗口,因为它看起来像Alfred没有作为窗口激活

set appName to "Alfred 3"
set is_start to false

tell application "System Events"
    if not (exists process appName) then
        set is_start to true
    else
        if visible of process appName then
            set visible of process appName to false
        else
            set frontmost of process appName to true
        end if
    end if
end tell

tell application "Alfred 3"
    reopen -- open a default window if there are no open windows
    activate -- make frontmost
end tell
需要一些帮助来找到解决方案

谢谢。

注意:阿尔弗雷德和键盘大师在功能上有重叠,使用其中一个就足够了

在编程方面,Alfred只提供激活,不提供停用:

告诉应用程序“Alfred 3”进行搜索#激活Alfred
您只能通过发送在Alfred自身中配置的全局热键来实现停用,以便在Alfred处于活动状态时切换其激活;默认情况下,该热键是⌥空间 :

使用{option down}告诉应用程序“系统事件”击键“”
因此,鉴于Alfred自己的热键是一个切换键,您需要做的就是:

使用{option down}告诉应用程序“系统事件”击键“”
注意事项:如果用于调用此AppleScript的键盘Maestro快捷键包含除切换Alfred所涉及的修改器之外的其他修改器,则此操作无效