pythonattributeerrorsourceforge-appscriptpy-appscript

appscript attribute error


I'm new to programming, and to 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. Testing along they way, I'm getting an AttributeError after acrobat opens the pdf, which trips the program before the OCR can happen. 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.


Solution

  • The activate command does not return an app reference. Try this:

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