Applescript “Google Chrome got an error: Can’t make |tabs| of window id 1 into type specifier.”

依然范特西╮ 提交于 2020-07-09 11:54:47

问题


New to Applescript.

Trying to make a script that will cycle through my tabs, printing each tab to PDF.

Starting from here...

Example of working Google Chrome Applescript

...but trying to generalize to work with all of Google Chrome, Firefox, and Safari. To start this modification, I began by looking here and here.

I'm getting tripped up right off the bat, noticing that a small change can make a big difference ...

NO ERROR:

tell application "Google Chrome"
    set myWindow to front window
    set myTabs to tabs in myWindow
    --Do more stuff here...
end tell

ERROR:

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

The error I'm getting is:

"Google Chrome got an error: Can’t make |tabs| of window id 1 into type specifier." The "offending object" in this error is "tabs of window id 1", and it's telling me that the expected type is "reference".

Any ideas how to proceed? Thanks for any help.

Justin

EDIT:

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

来源:https://stackoverflow.com/questions/61766543/applescript-google-chrome-got-an-error-can-t-make-tabs-of-window-id-1-into-t

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!