gpt4 book ai didi

applescript - 按文档文件名访问窗口

转载 作者:行者123 更新时间:2023-12-04 06:40:59 27 4
gpt4 key购买 nike

我没有在 applescript 中做太多编程,但我有一个个人应用程序,它主要是 python,但生成简单的 applescripts 并通过系统调用调用它们。 Applescript 与我通常编程的语言是如此不同,以至于我无法弄清楚我是如何...

获取应用程序中文档的窗口顺序?

用于调用电话,例如:

set bounds of **first** window to %s

换句话说,我怎样才能获得应用程序的文档“窗口顺序”?

是否可以通过像这样访问文档来与窗口交互:
to get bounds of first window whose document is "%s"

(这不起作用)还是我必须先获取文档的窗口顺序,然后在第二行与该窗口(通过其顺序)进行交互?

任何见解都会很棒。谢谢。

最佳答案

你可以很好地完成这两件事。第一行只是 set bounds of window 1 to ... ,或者,如果您愿意,set bounds of the first window to ...第二个取决于你想要做什么。如果您想访问第一个名称特别重要的窗口,您可以执行 get the bounds of window "NAME" ;但是,如果您真的想要文档的名称,则需要执行类似的操作

set d to the document "NAME"
repeat with w in windows
if w's document is d then return bounds of w
end repeat

你应该可以做 the first window whose document is d ,但这失败了;据我所知,这是因为 document也是一个类型名称。此外,如果 window "NAME"/ document "NAME"失败——这是我记得有时不起作用的那种事情,即使它应该——你可以改用 the first window whose name is "NAME" (或 the first document ... )。但简单的形式几乎肯定会起作用。

另外,如果你只是生成这些 AppleScripts,调用它们,然后删除它们——换句话说,如果你假装它们是 Python 函数,而不是生成它们以供以后使用——我强烈推荐使用 appscript。反而,。我从未在 Python 中使用过 in ,但我在 Ruby 中使用过,它是处理 AppleScript 所做的一切同时仍使用您选择的语言的一种非常好的方式。例如,我认为您的第一个示例将变为 app('Whatever').windows[1].bounds.set((0,0,0,0)) , (或 ...windows.first.... 如果您愿意),您的第二个将变为 app('Whatever').windows['NAME'].bounds.get()app('Whatever').windows[its.document.name == 'NAME'].get() ,取决于您是否需要窗口的名称或窗口的文档名称。这一切都未经测试,但肯定捕捉到了 appscript 的风格(简洁明了)。

关于applescript - 按文档文件名访问窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4236121/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com