基本上,我的目标是编写一个按键命令(选项-s)来激活粘贴纸并创建一个新的便笺。现在,我有一个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这两个activate命令是我尝试处理的一个bug,它会打开应用程序,但不会把它带到前面。当应用程序在后台打开时,它可以无缝工作,但速度很慢,并且在应用程序尚未运行时会产生屏幕闪烁。延迟不是来自应用程序本身,因为我可以打开应用程序并尽可能快地点击命令-n,而且它总是有效的。
(顺便说一句,如果你有一个想法,我可以隐藏所有其他笔记,只显示新的笔记,那就太棒了!)
发布于 2014-03-05 18:14:46
试试这个:
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。
或者,这不会提高其他注释的窗口:
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中,热键的默认延迟也很短,但您可以通过更改触发器行为来减少延迟:

发布于 2014-03-05 17:44:08
你可以尝试这种替代方法,可能会有不同的效果。
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隐藏所有其他笔记,我会说开始一个新的问题。
https://stackoverflow.com/questions/22187559
复制相似问题