通过文档文件名访问窗口

发布于 2024-10-03 09:18:43 字数 464 浏览 3 评论 0原文

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

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

对于拨打电话

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

换句话说,我如何获取应用程序的文档“窗口顺序”?

是否可以通过访问文档来与窗口交互,就像这样:(

to get bounds of first window whose document is "%s"

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

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

I don't do much programming in applescript but I have a personal app which is mostly python but generates simple applescripts and calls them via a system call. Applescript is so different from the languages I usually program in that I can't figure out how I...

get the window order of a document within an application?

For making calls like:

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

in other words, how can I get the document's "window order" for an application?

Is it possible to interact with a window through accessing the document like this:

to get bounds of first window whose document is "%s"

(which doesn't work) or do I have to get the document's window order first and then interact with that window (via its order) in a second line?

Any insight would be great. Thanks.

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

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

发布评论

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

评论(1

你在看孤独的风景 2024-10-10 09:18:43

这两件事你都可以做得很好。第一行只是将窗口 1 的边界设置为...,或者,如果您愿意,将第一个窗口的边界设置为... 第二行取决于你到底想做什么。如果你想访问第一个名称特殊的窗口,你可以获取窗口“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

您应该能够执行 第一个文档为 d 的窗口,但这会失败;据我所知,这是因为 document 也是一个类型名称。另外,如果 window "NAME"/document "NAME" 失败——我记得有时会出现这种情况,即使它应该起作用——你也可以使用 < code>名称为“NAME”的第一个窗口(或第一个文档...)。但简单的形式几乎肯定会起作用。

另外,如果您只是生成这些 AppleScript、调用它们并删除它们(换句话说,如果您假装它们是 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 的风格(漂亮而简洁)。

You can do both of these things just fine. The first line is just set bounds of window 1 to ..., or, if you prefer, set bounds of the first window to ... The second one depends on what, exactly, you want to do. If you want to access the first window whose name is something in particular, you can just do get the bounds of window "NAME"; if you really want the name of the document, though, you'll need to do something like

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

You should be able to do the first window whose document is d, but this fails; as far as I can tell, it's because document is also a type name. Also, if window "NAME"/document "NAME" fails—it's the sort of thing that I remember sometimes not working, even though it should—you can instead use the first window whose name is "NAME" (or the first document ...). But the simple form will almost certainly work.

Also, if you're just generating these AppleScripts, calling them, and deleting them—in other words, if you're pretending they're Python functions, rather than generating them for later use—I'd highly recommend using appscript instead,. I've never used in in Python, but I have in Ruby, and it's a really great way to deal with everything AppleScript does while still using your language of choice. For instance, I think your first example would become app('Whatever').windows[1].bounds.set((0,0,0,0)), (or ...windows.first.... if you prefer) and your second would become either app('Whatever').windows['NAME'].bounds.get() or app('Whatever').windows[its.document.name == 'NAME'].get(), depending on if you need the window's name or the window's document's name. This is all untested, but certainly captures the flavor of what appscript tends to look like (nice and concise).

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