有没有办法获得任何给定窗口的永久标识符

发布于 2024-11-13 23:36:47 字数 729 浏览 0 评论 0原文

我正在尝试编写一个脚本,可以从不同的程序控制不同的窗口(设置位置和大小)。我已经完成了工作,但在准确识别窗口时遇到问题。现在我已经得到:

tell application "System Events"
    tell application "Mail"
        set windowName to name of window 1
    end tell
end tell

这是我现在工作的一个相当简化的版本。我正在抓取许多不同应用程序的窗口信息,并将它们存储为稍后由另一个脚本调用的属性:

tell application "System Events"
    tell application "Mail"
        set position of window windowName to valueX
    end tell
end tell

只要窗口的名称不更改,这就可以工作。在许多其他应用程序中我没有遇到任何问题,因为窗口标题不会改变(iCal、iChat 等)。在“邮件”中,窗口标题会根据电子邮箱中的电子邮件数量而变化。如果电子邮件出现在脚本的第一部分和最后一部分之间,则脚本将失败。

我无法真正通过窗口的索引号来引用窗口,因为这些索引号会随着窗口顺序的变化(从前到后)而变化。我认为窗口 ID 可能会起作用,但即使应用程序已退出并重新启动,并且重新启动应用程序时 ID 号会发生变化,我也需要我的脚本能够工作。我是SOL,还是有什么我没有想到的?

I'm trying to write a script that can control different windows from different programs (set position and size). I've got things just about working but I'm having problem accurately identifying windows. Right now I've got:

tell application "System Events"
    tell application "Mail"
        set windowName to name of window 1
    end tell
end tell

This is a pretty simplified version of what I have working now. I'm grabbing the window information for many different applications and storing them as properties which are being called upon by another script later:

tell application "System Events"
    tell application "Mail"
        set position of window windowName to valueX
    end tell
end tell

This works as long as the name of the window doesn't change. In many other applications I have no problems because window titles don't change (iCal, iChat, etc). In Mail the window title changes depending on how many e-mails are in your e-mail box. If an e-mail comes in between the first part of the script and the last then the script fails.

I can't really refer to the window by it's index number because those change as the order of the windows change (front to back). I thought maybe the window ID would work, but I need my script to work even if an application has been quit and restarted and the ID number changes if the application is relaunched. Am I SOL, or is there something I hadn't thought of?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国际总奸 2024-11-20 23:36:47

不是 SOL,但您还需要做更多的工作。窗户只有几种类型。您有主浏览器窗口和电子邮件,无论是他们正在撰写的草稿还是他们正在阅读的电子邮件。也许您也关心首选项窗口。所以你必须存储窗口的类型。如果它是浏览器,那么您还必须存储当前选择的消息。如果是电子邮件窗口,那么您也可以存储消息 ID。对于浏览器,您只需打开一个新的浏览器窗口并恢复选择。对于电子邮件消息,您只需打开消息即可。您必须检查邮件字典中是否有其他类型的窗口,但想法是相同的。

Not SOL, but you'll have to do a little more work. There's only a few types of windows. You have the main browser window and you have email messages, whether it be a draft they are composing or an email message they're reading. Maybe you're concerned with the preferences window too. So you have to store the type of window. If it's a browser then you also will have to store the currently selected message. If it's an email window then you store the message id too. For browsers you just open a new browser window and restore the selection. For email messages you just open the messages. You'll have to check Mail's dictionary for other types of windows, but the idea will be the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文