Dav*_*man 7 macos applescript google-chrome window-management
有没有办法让AppleScript访问右键单击停靠栏图标时出现的菜单项?
具体来说,这就是我想要做的事情:
我在MacOS X Snow Leopard上使用谷歌浏览器作为我的网络浏览器.我是键盘快捷键上瘾者,我使用QuickSilver为我能做的任何事情创建键盘快捷键.我做的最常见的事情之一是打开一个新的Web浏览器窗口.但是我经常使用Spaces来分区我正在处理的任务,当我打开带有QuickSilver触发器的Web浏览器或网页时,空格切换到我使用Chrome的最后一个空格并打开一个新标签,这通常是分散了我几个小时的注意力,因为它把我带到了不同的空间,从而完成了不同的任务.我可以通过右键单击Google Chrome图标并单击"新窗口"选项来解决此问题,该选项会在当前空间中打开一个新窗口.但是在AppleScript中,要对谷歌Chrome做任何事情,我要做的第一件事就是激活它,这让我回到原来的问题!任何人都可以想到这个问题的解决方案,AppleScript或其他?这已经成为一个严重的问题.回到我使用Firefox的时候,我通过改变一个首选项来解决这个问题,该首选项说"总是在新窗口中打开弹出链接"或类似的东西,这是一种大锤方法,但它起作用了.我总是可以回到Firefox,但我想我先问我的问题.有想法的人吗?
Geo*_*rge 15
不确定你是否还有兴趣,但......
tell application "Dock"
activate
end tell
tell application "System Events"
tell process "Dock"
set frontmost to true
activate
tell list 1
perform action "AXShowMenu" of UI element "Google Chrome"
delay 1
repeat 4 times -- count number of items to the one you want
key code 126 -- up arrow
-- key code 125 -- down arrow
end repeat
delay 1
repeat 2 times
key code 36 -- return key
end repeat
end tell
end tell
end tell
Run Code Online (Sandbox Code Playgroud)
作为最受支持的答案的变体,这里有一个接受菜单项名称的脚本版本,它可以让您避免进行任何计数。
\n\n此示例从 Finder 的停靠菜单中单击“转到文件夹...”。
\n\ntell application "Dock"\n activate\nend tell\ntell application "System Events"\n tell process "Dock"\n set frontmost to true\n activate\n tell UI element "Finder" of list 1\n perform action "AXShowMenu"\n click menu item "Go to Folder\xe2\x80\xa6" of menu "Finder"\n end tell\n end tell\nend tell\n
Run Code Online (Sandbox Code Playgroud)\n
对于任何感兴趣的人,我认为我已经为这个问题找到了一个合理的工作解决方案,但它不涉及右键单击停靠图标。
首先,您必须在“系统偏好设置”的“空间”偏好设置窗格中取消选中“切换到应用程序时,切换到该应用程序打开的窗口的空间”。然后我编写了以下 AppleScript:
tell application "Google Chrome" to activate
tell application "System Events"
tell process "Google Chrome"
try
set var to get name of window 1
on error
set var to "no window exists!!!"
end try
end tell
end tell
if var is "no window exists!!!" then
tell application "System Events"
tell process "Google Chrome"
click menu item "New Window" of menu "File" of menu bar 1
end tell
end tell
else
tell application "System Events"
tell process "Google Chrome"
click menu item "New Tab" of menu "File" of menu bar 1
end tell
end tell
end if
Run Code Online (Sandbox Code Playgroud)
我使用Spark启动此 AppleScript ,它允许我为其分配快捷键。
它有点慢,特别是当系统处于负载状态时,但通常运行时间不会超过一秒左右。它还避免了我在使用 Firefox 时遇到的问题,即一天结束时我会打开数十个窗口。
归档时间: |
|
查看次数: |
4682 次 |
最近记录: |