我将 Applescript 与 Alfred 结合使用在 Billings 中提供用于启动和停止计时器的键盘快捷键。这对于我跟踪我的自由职业非常有用。
这是我正在使用的代码:
tell application "Billings" to activate
tell application "System Events"
tell process "Billings"
tell menu bar 1
tell menu bar item "Slips"
tell menu "Slips"
if menu item "Start Timer" exists then
click menu item "Start Timer"
else
click menu item "Stop Timer"
end if
end tell
end tell
end tell
keystroke "h" using {command down}
end tell
end tell
我已将其弹出到 Alfred 扩展集中,以使用 CTRL+ALT+CMD+T 激活。
不幸的是,它有点笨拙。在昨天之前我从未接触过Applescript,所以我担心我的能力有点差。比林斯窗口立即弹出到前台,然后再次隐藏。如果碰巧按下键盘上除 H 之外的任何修饰键,它也不会隐藏。
因此:
- 是否有更好的方法来调用 Billings,使其不会弹出?
- 如果没有,是否有更好的方法来隐藏它并返回到之前获得焦点的应用程序。
为清楚起见进行编辑: Billings 是一个 OSX 自由时间跟踪和发票软件包。我使用计时器来跟踪我在每项任务上花费的时间,以便我可以准确地向客户计费。我个人觉得非常有用。计时器(针对我正在处理的当前项目)显示在菜单栏中,并且可以通过单击鼠标进行切换。理想情况下,当 Billings 不在前台时,我可以使用键盘快捷键轻松启动和停止它,但没有内置功能可以执行此操作。它看起来像这样:
最佳答案
这是使应用程序保持在后台的解决方案。
-- no activate
tell application "System Events"
tell group 1 of group 2 of window "Billings" of process "Billings"
perform action "AXPress" of (get first button whose its name ends with " Timer")
end tell
end tell
--
如果不起作用,这里是不使用快捷方式隐藏应用程序的解决方案
activate application "Billings"
tell application "System Events"
tell process "Billings"
tell menu "Slips" of menu bar item "Slips" of menu bar 1
click (get first menu item whose its name ends with " Timer")
end tell
set visible to false
end tell
end tell
关于scripting - 我可以使用 Applescript 来控制程序而不将该程序带到前台吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10636511/