Search code examples
applescriptacrobat

closing pop up with AppleScript


I'm using AppleScript to convert a bunch of PDF files to TXT files:

set homeFolder to path to home folder as text
set sourceFolder to homeFolder & "pdffolder:"
set txtFolder to homeFolder & "txtfolder:"

tell application "Finder"
    set fileSet to get every file of folder sourceFolder
end tell

activate application "Adobe Acrobat Pro"
repeat with aFile in fileSet
    set currentFile to aFile as text
    set currentFileName to name of aFile
    set outFile to txtFolder & text 1 thru -5 of currentFileName & ".txt"
    with timeout of 360000 seconds
        tell application "Adobe Acrobat Pro"
            open currentFile
            try
                save active doc to file outFile using conversion "com.adobe.acrobat.plain-text"
                close active doc saving no
            on error
                tell application "System Events" to tell application "Adobe Acrobat Pro"
                    keystroke return
                end tell
            end try
        end tell
    end timeout
end repeat

This works fine for over 90% of the PDFs. But some of them have weird characters and that results in the following pop up:

enter image description here How do I dismiss that pop up in AppleScript? That on error clause in my script was supposed to do that but it doesn't work. Maybe because the pop up is not an error but, well, a pop up; but I have no idea how to treat it.

EDIT:

This is the closest I got to it:

set homeFolder to path to home folder as text
set sourceFolder to homeFolder & "pdffolder:"
set txtFolder to homeFolder & "txtfolder:"

tell application "Finder"
    set fileSet to get every file of folder sourceFolder
end tell

activate application "Adobe Acrobat Pro"
repeat with aFile in fileSet
    set currentFile to aFile as text
    set currentFileName to name of aFile
    set outFile to txtFolder & text 1 thru -5 of currentFileName & ".txt"
    with timeout of 120 seconds
        tell application "Adobe Acrobat Pro"
            open currentFile
            try
                save active doc to file outFile using conversion "com.adobe.acrobat.plain-text"
                close active doc saving no
            on error
                tell application "System Events" to tell process "Notification Center"
                    keystroke return
                end tell
                close active doc saving no
            end try
        end tell
    end timeout
end repeat

So, I'm forcing a timeout error after the pop up has hanged there for 120 seconds. I handle that error by making keystroke return, which dismisses the pop up and keeps the loop moving forward. But still, ugly as hell - and the 120-second wait slows things down.


Solution

  • Unfortunately it's impossible.

    If an Acrobat error occurs the save line is suspended and the dialog window appears. Practically the script hangs in the save line and resumes after the user clicks the OK button. An AppleScript error is not thrown.