【问题标题】:Using Applescript to Search PDFs with Safari使用 Applescript 通过 Safari 搜索 PDF
【发布时间】:2013-05-17 11:37:51
【问题描述】:

我有大约 1000 个链接到远程 PDF 文件的 URL,我需要确定哪些可以被 Safari 搜索,哪些不能。我有我的脚本循环并在 Safari 中打开 URL,但我被困在下面的最后 2 个步骤中。

有人可以帮忙吗?谢谢

脚本需要:

对于每个网址:

告诉 Safari

  1. 打开给定的 URL(在本例中为远程 PDF)
  2. 在 PDF 中搜索字符“a” 使用右键单击时弹出的查找,而不是 Apple F

  3. 将搜索结果写入文件

      set urlList to {"http://pricelist.list.com/pricelists/A/AEA_11-15-12.pdf", "http://pricelist.list.com/pricelists/A/API_1608_04-05-13.pdf", "http://pricelist.list.com/pricelists/A/Access_02-01-12.pdf", "http://pricelist.list.com/pricelists/A/Allparts_Retail_01-01-11.pdf"}
       set numURLs to (count urlList)
       repeat with i from 1 to (numURLs)
    
    set theURL to (item i of urlList)
    tell application "Safari"
        open location theURL
        activate
        --Perform search
        --Write results to file
    end tell
    tell application "System Events"
        tell process "Safari"
            click menu item "Close Other Tabs" of menu "File" of menu bar 1
        end tell
    end tell
    delay 5
    

    结束重复

【问题讨论】:

    标签: pdf safari applescript


    【解决方案1】:

    下载 PDF 和使用 shell 脚本可能更容易:

    brew install poppler wget parallel
    cat ~/Documents/urls.txt | parallel -P8 wget
    for f in *.pdf; do [[ $(pdffonts -- "$f" 2> /dev/null | wc -l) -eq 2 ]] && printf %s\\n "$f"; done
    

    pdffonts 为没有嵌入字体的扫描 PDF 打印两行输出。见How do I determine programmatically if a PDF is searchable?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-03
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多