使用 AppleScript 访问停靠栏图标右键单击菜单项 [英] Accessing dock icon right-click menu items with AppleScript

查看:26
本文介绍了使用 AppleScript 访问停靠栏图标右键单击菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以让 AppleScript 访问在您右键单击停靠栏图标时出现的菜单项吗?

Is there any way to get an AppleScript to access the menu items that come up when you right click on a dock icon?

具体来说,这是我想要做的:

Specifically, here's what I want to do:

我在 MacOS X Snow Leopard 上使用 Google Chrome 作为我的网络浏览器.我是一个键盘快捷键上瘾者,我使用 QuickSilver 为任何我可以创建的键盘快捷键创建.我做的最常见的事情之一是打开一个新的 Web 浏览器窗口.但是我经常使用 Spaces 来划分我当前正在处理的任务,当我使用 QuickSilver 触发器打开网络浏览器或网页时,Spaces 会切换到我使用 Chrome 的最后一个空间并打开一个新标签页,这通常是让我分心了几个小时,因为它把我带到了一个不同的空间,从而完成了不同的任务.我可以通过右键单击 Google Chrome 图标并单击新窗口"选项来解决此问题,这会在当前空间上打开一个新窗口.但是在 AppleScript 中,要使用 Google Chrome 做任何事情,我要做的第一件事就是激活它,这让我又回到了最初的问题!任何人都可以想出解决这个问题的方法,AppleScript 或其他?它已成为一个严重的问题.回到我使用 Firefox 时,我通过更改始终在新窗口中打开弹出链接"或类似内容的首选项来解决该问题,这是一种大锤方法,但它有效.我总是可以回到 Firefox,但我想我会先在这里问我的问题.有人有任何想法吗?

I use Google Chrome as my web browser on MacOS X Snow Leopard. I am a keyboard shortcut addict, and I use QuickSilver to create keyboard shortcuts for anything I can. One of the most common things that I do is to open a new web browser window. But I use Spaces frequently to partition my tasks that I am currently working on, and when I open a web browser or web page with a QuickSilver trigger, spaces switches to the last space that I used Chrome on and opens a new tab, which often distracts me for hours because it brings me to a different space and thus a different task. I can fix this by right-clicking on the Google Chrome icon and clicking the "New Window" option, which opens a new window on the current space. But in AppleScript, to do anything with Google Chrome, the first thing I have to do is activate it, which brings me back to the original problem! Can anyone think of a solution to this problem, AppleScript or otherwise? It has become a serious problem. Back when I used Firefox, I solved the problem by changing a preference item that says "Always open pop-up links in a new window" or something like that, which was kind of a sledge hammer approach, but it worked. I can always go back to Firefox, but I thought I'd ask my question here first. Anyone with any ideas?

推荐答案

对于任何有兴趣的人,我想我已经有了解决这个问题的合理可行的解决方案,但它不涉及右键单击停靠栏图标.

For anyone who is interested, I think I've got a reasonable working solution to this problem, but it doesn't involve right-clicking on dock icons.

首先,您必须在系统偏好设置"的空间"偏好设置面板中取消选中切换到应用程序时,切换到应用程序打开的窗口的空间".然后我写了以下 AppleScript:

First, you have to uncheck "When switching to an application, switch to a space with open windows for the application" in the Spaces preference pane of System Preferences. Then I wrote the following 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

我使用 Spark 启动这个 AppleScript,它允许我指定一个快捷键到它.

I launch this AppleScript using Spark, which allows me to assign a shortcut key to it.

它有点慢,特别是当系统处于负载下时,但通常运行时间不会超过一秒左右.它还避免了我在使用 Firefox 时遇到的问题,我最终会在一天结束时打开数十个窗口.

It's a little bit slow, particularly when the system is under a load, but usually doesn't take longer than a second or so to run. It also avoids the problem I was having with Firefox, where I would end up with dozens of windows open at the end of the day.

这篇关于使用 AppleScript 访问停靠栏图标右键单击菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆