【问题标题】:Delay in an Alfred 2, using Automator and Apple Script to open "Stickies" and create a new noteAlfred 2 中的延迟,使用 Automator 和 Apple Script 打开“Stickies”并创建新笔记
【发布时间】:2014-03-05 18:14:45
【问题描述】:

基本上,我的目标是编写一个键盘命令(选项-s)来激活 Stickies 并创建一个新笔记。现在我有一个 Alfred 2 生成的自动化,它将热键链接到以下脚本:

on alfred_script(q)
    tell application "Stickies" to activate
    delay .2
    tell application "Stickies" to activate
    delay .01
    tell application "System Events"
        keystroke "n" using command down
    end tell
end alfred_script

这两个激活命令是我尝试处理打开应用程序但没有将其置于最前面的错误。当应用程序在后台打开时,它可以无缝运行,但速度很慢,并且在应用程序尚未运行时会创建屏幕闪烁。延迟不是来自应用程序本身,因为我可以尽快打开应用程序并按 command-n,而且它始终有效。

(顺便说一句,如果你知道我可以如何隐藏所有其他笔记并只显示新笔记,那就太棒了!)

【问题讨论】:

    标签: applescript workflow sticky alfred


    【解决方案1】:

    试试这个:

    launch application "Stickies"
    tell application "System Events" to tell process "Stickies"
        click menu item "New Note" of menu "File" of menu bar 1
        set frontmost to true
    end tell
    

    如果您通过按 option-s 来运行脚本,则在keystroke "n" using command down 之前可能没有足够的时间来释放选项。

    或者这不会提高其他笔记的窗口:

    launch application "Stickies"
    tell application "System Events" to tell process "Stickies"
        click menu item "New Note" of menu "File" of menu bar 1
    end tell
    do shell script "open -a Stickies"
    

    activate app "Appname"set frontmost of "Appname" to true 启动所有窗口,但 do shell script "open -a Appname" 仅启动一个窗口。

    默认情况下,热键在​​ Alfred 中也有短暂的延迟,但您可以通过更改触发行为来减少它:

    【讨论】:

      【解决方案2】:

      你可以试试这个替代方法,可能会有不同的效果。

      tell application "System Events"
          tell process "Stickies"
              set frontmost to true
              keystroke "n" using command down
              keystroke "Hello World" & linefeed & "I'm a new note!"
          end tell
      end tell
      

      隐藏所有其他注释,我会说为此开始一个新问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        • 1970-01-01
        • 1970-01-01
        • 2014-08-24
        相关资源
        最近更新 更多