首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Alfred 2中的延迟,使用Automator和Apple Script打开"Stickies“并创建新笔记

Alfred 2中的延迟,使用Automator和Apple Script打开"Stickies“并创建新笔记
EN

Stack Overflow用户
提问于 2014-03-05 10:55:42
回答 2查看 645关注 0票数 0

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

代码语言:javascript
复制
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

这两个activate命令是我尝试处理的一个bug,它会打开应用程序,但不会把它带到前面。当应用程序在后台打开时,它可以无缝工作,但速度很慢,并且在应用程序尚未运行时会产生屏幕闪烁。延迟不是来自应用程序本身,因为我可以打开应用程序并尽可能快地点击命令-n,而且它总是有效的。

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

EN

回答 2

Stack Overflow用户

发布于 2014-03-05 18:14:46

试试这个:

代码语言:javascript
复制
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之前释放option。

或者,这不会提高其他注释的窗口:

代码语言:javascript
复制
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中,热键的默认延迟也很短,但您可以通过更改触发器行为来减少延迟:

票数 1
EN

Stack Overflow用户

发布于 2014-03-05 17:44:08

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

代码语言:javascript
复制
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

隐藏所有其他笔记,我会说开始一个新的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22187559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档