AppleScript 和不可编写脚本的应用程序

发布于 2024-11-03 17:39:25 字数 252 浏览 1 评论 0原文

我想知道如何编写没有字典的应用程序脚本。我找到的所有信息都没有告诉我任何信息。但我的经验告诉我,有办法。 例如:

tell application "Firefox"
    return count of windows
end tell

会工作。它可以与“Opera”和其他应用程序一起使用,而无需字典。所以问题是: 1)为什么它有效? 2)还有什么以这种方式工作?有所有此类行动的清单吗?

预先感谢!

I'm wondering how can I script applications which has no dictionary. All information that I've found tells me nothing. But my experience says me that there is a way.
For example:

tell application "Firefox"
    return count of windows
end tell

Will work. And it will work with "Opera" and other applications without dictionary at all. So the questions are:
1) Why does it work?
2) What else work in such a manner? Is there a list of all such actions?

Thank in advance!

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

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

发布评论

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

评论(2

罗罗贝儿 2024-11-10 17:39:26

您可以在某种程度上通过使用“告诉应用程序“系统事件””来编写没有 applescript 字典的应用程序脚本。

tell application "Keynote" activate 
tell application "System Events" to keystroke "c" using {command down} 
end tell
end tell

此示例激活 Keynote,然后复制当前选择。您可以在许多应用程序中使用类似的代码,即使它们没有 applescript 字典,前提是您还在“通用访问”系统偏好设置中选中了“启用辅助设备的访问”选项。

编辑:

本文档详细介绍了 Cocoa 如何在所有应用程序中为 Applscript 提供一些支持:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_about_apps/SAppsAboutApps.html

在标准和文本套件的内置支持标题下

You can to some extent script applications without an applescript dictionary by using 'tell application "System Events"'

tell application "Keynote" activate 
tell application "System Events" to keystroke "c" using {command down} 
end tell
end tell

This example activates Keynote and then copies the current selection. You can use similar code in many applications even if they don't have an applescript dictionary provided you also have the "Enable access for assistive devices" option checked in the "Universal Access" System Preference.

Edit:

This document gives some details of how Cocoa provides some support for Applscript in all applications:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_about_apps/SAppsAboutApps.html

Under the heading Built-in Support for Standard and Text Suites

柠栀 2024-11-10 17:39:26

可以打开FireFox的脚本字典。只需打开 AppleScript 编辑器并转到“文件”→“显示字典”,然后从列表中选择“FireFox”。

它只是显示了一本非常基本的字典。所发生的情况是,系统库至少为任何 Carbon 或 Cocoa 应用程序提供了一组基本命令(称为标准套件)。这包含您使用的 window 的定义。

正如 Ian 已经写过的,为了使用此类应用程序执行更多操作,您可以通过系统事件使用所谓的UI 脚本
这个不错的网站是一个很好的起点。

You can open the scripting dictionary of FireFox. Just open AppleScript Editor and go File → show dictionary, and choose FireFox from the list.

It just shows a very rudimentary dictionary. What happens is that the system library provides at least a basic set of commands (called the Standard Suite) to any Carbon or Cocoa app. This is what contains the definitions of window you used.

As Ian already wrote, in order to do more with such an app, you use the so-called UI scripting via System Events.
This nice website is a good place to start.

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