gpt4 book ai didi

applescript - AppleScript-Safari帮助

转载 作者:行者123 更新时间:2023-12-02 04:06:37 27 4
gpt4 key购买 nike

我已被任命创建一个必须

  • 当网页加载完
  • 后,显示一个对话框,显示 "The webpage has finished loading."
  • 确定当前正在下载
  • 的项目数量

    对于数字1,我​​尝试做 if the URL of the front document is "http://applescript.weebly.com" then,但是即使网页未加载, then部分也始终运行!

    对于2号,我已经尝试过了...
    tell application "Safari" to get every item of window "Downloads"

    但这会返回每个项对 的引用,甚至包括已经下载的项!

    结论:我需要帮助。 :S

    最佳答案

    网页加载完成后,显示一个对话框,显示"The webpage has finished loading."

    仅使用纯AppleScript是无法做到这一点的。但是,您可以结合使用AppleScript和javascript ...

    tell application "Safari"
    repeat until (do JavaScript "document.readyState" in document 1) is "complete"
    end repeat
    display dialog "The webpage has finished loading."
    end tell

    警告:如果网页由于某种原因未加载,则脚本将永远陷入无限循环。

    确定当前正在下载的项目数。

    下载文件时,它们会临时获得扩展名 download,因此AppleScript可以告诉Finder获取具有该扩展名的文件并创建警报/对话框:
    set the download_count to 0
    set the download_folder to (path to downloads folder) as alias --or wherever the items are being downloaded
    tell application "Finder" to set the download_count to the count of (every item of the download_folder whose name extension is "download")
    if the download_count is 0 then
    display dialog "There are currently no downloads in progress."
    else if the download_count is 1 then
    display dialog "There is currently one download in progress."
    else
    display dialog "There are currently " & the download_count & " downloads in progress."
    end if

    P.S. 感谢您纪念我的网站!

    关于applescript - AppleScript-Safari帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7300100/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com