【发布时间】:2020-05-13 04:37:00
【问题描述】:
Applescript 新手。
尝试制作一个脚本,循环浏览我的标签,将每个标签打印为 PDF。
从这里开始……
Example of working Google Chrome Applescript
...但试图概括以适用于所有 Google Chrome、Firefox 和 Safari。为了开始这个修改,我首先查看了here 和here。
我马上就被绊倒了,我注意到一个小小的改变可以产生很大的不同......
没有错误:
tell application "Google Chrome"
set myWindow to front window
set myTabs to tabs in myWindow
--Do more stuff here...
end tell
错误:
set webBrowser to "Google Chrome"
tell application webBrowser
set myWindow to front window
set myTabs to tabs in myWindow
--Do more stuff here...
end tell
我得到的错误是:
“Google Chrome 出现错误:无法将窗口 ID 1 的 |tabs| 设置为类型说明符。”此错误中的“违规对象”是“窗口 id 1 的选项卡”,它告诉我预期的类型是“引用”。
任何想法如何进行?感谢您的帮助。
贾斯汀
编辑:
set webBrowser to "Firefox" -- or Safari
set pdfMenuItemTitle to "Save as PDF…" -- the title of the menu item you want
set myDelay to 0.2
tell application webBrowser to activate
tell application "System Events"
tell process webBrowser
-- open the print dialog
click menu item "Print…" of menu 1 of menu bar item "File" of menu bar 1
delay myDelay
--Do more stuff here...
end tell
end tell
【问题讨论】:
-
变量不能用于tell语句的目标 - 任何给定应用程序的脚本术语都需要在编译时声明。
-
@red_menace ...感谢您的回复:)。快速的问题,不过...查看我的编辑...为什么 EDIT 部分代码有效?
-
之所以有效,是因为您没有使用应用程序的脚本术语,而是通过系统事件(在编译时声明)为用户界面编写脚本。
标签: applescript