简体   繁体   English

appscript 属性错误

[英]appscript attribute error

I'm new to programming, and to python.我是编程和 python 的新手。 I'm trying to use appscript in a python script to choose a pdf and a new destination folder, open the pdf in Adobe Acrobat Pro, OCR it, and save it in the new folder.我正在尝试在 python 脚本中使用 appscript 来选择一个 pdf 和一个新的目标文件夹,在 Adob​​e Acrobat Pro 中打开 pdf,对其进行 OCR,并将其保存在新文件夹中。 Testing along they way, I'm getting an AttributeError after acrobat opens the pdf, which trips the program before the OCR can happen.一路上进行测试,我在 acrobat 打开 pdf 后收到 AttributeError,这会在 OCR 发生之前触发程序。 Here's the code:这是代码:

import easygui, os, time, mactypes
from appscript import *

fileURL = easygui.fileopenbox(filetypes=["*.pdf"])
time.sleep(1)
destDir = easygui.diropenbox()


acrobat = app('Adobe Acrobat Pro').activate()
acrobat.open(fileURL)

And, here's the error traceback:而且,这是错误回溯:

Traceback (most recent call last):
  File "/Users/chadblack/Dropbox/001-DH_Scripts/splitOCRpdf.py", line 19, in <module>
    acrobat.open(fileURL)
AttributeError: 'NoneType' object has no attribute 'open'

Note, the pdf DOES open in Acrobat, that attribute error breaks the script.请注意,pdf 确实在 Acrobat 中打开,该属性错误会破坏脚本。

The activate command does not return an app reference. activate命令不返回app引用。 Try this:尝试这个:

acrobat = app('Adobe Acrobat Pro')
acrobat.activate()
acrobat.open(fileURL)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM