AppleScript单击确定并从Firefox链接保存文件

问题描述 投票:0回答:2

所以我有一个页面上有大约60个链接,随机URL,每个都需要单独点击和下载。

我正在研究基本脚本以切换到下一个链接,按Enter键,然后'确定'下载到桌面。

我是新手,但我似乎无法弹出“浮动”窗口,让我按键“返回”或点击“确定”。我想将文件保存到桌面,但我似乎无法在应用程序中按标题引用窗口,或猜测索引号或窗口ID。

任何帮助深表感谢..

我还在脚本编辑器中看到了字典,以及Firefox的“窗口”的许多属性,抛出语法和其他错误。

tell application "System Events"
tell application "Firefox" to activate
tell window "$thewindowtitle"
    keystroke tab
    delay 1.0
    keystroke return
end tell
tell application "Firefox"
    tell window visible
    click button "OK"
    end tell
end tell
end tell
end tell

谢谢!

applescript
2个回答
0
投票

Firefox似乎不支持运行JavaScripts,但在Safari中,您可以使用这样的脚本来获取所有链接的URL:

set l to {}
tell application "Safari" to tell document 1
    set n to do JavaScript "document.links.length"
    repeat with i from 0 to (n - 1)
        set end of l to (do JavaScript "document.links[" & i & "].href")
    end repeat
end tell
set text item delimiters to linefeed
set the clipboard to l as text

然后在默认浏览器中打开它们:

IFS=$'\n' for u in $(pbpaste); do open "$u"; done

或者使用curl:

cd ~/Desktop/; IFS=$'\n'; for u in $(pbpaste); do; curl "$u" -O; done

0
投票

从另一端看到这一点。在首选项> Firefox首选项>常规>应用程序中,我从ask更改为保存位置,选择Firefox处理您下载的文件的方式。它只是拯救了他们。在我的例子中,我在Automator中创建了一个工作流程,用于从url下载图像。这对我来说非常有用。

© www.soinside.com 2019 - 2024. All rights reserved.