You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript in Automator fails to execute

using os 12.0.1 and executing the following Automator script, AppleScript task fails to execute, but result shows successful execution

the task ends but fails to run the AppleScript. If I click the applescript execute button the AppleScript executes successfully. I have initially tried to run this script using the inFile parameter to set the file name, result is the same, script ends with out executing.



iMac 24″, 12.0

Posted on Nov 29, 2021 8:09 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 1, 2021 6:58 AM

The code shown is the relevant part of the script, there is much more to it, the result of the script adds a line of data to a Numbers sheet. That is why it appears that I do nothing with the variables. I know Automator fails to execute the script because Automator ends with the green check and "Workflow completed" message and displays the input file in the results box, but no data added to the spreadsheet nor are any other messages displayed. If, after Automator completes and with out exiting, I click the AppleScript execute button, the script executes successfully and adds the information to the spreadsheet.


I have also tried a version of this script trying to use the file passed from the Preview "Extract PDF Data" step, and the script fails to run, with the same results, Automator completes successfully but no update to the spreadsheet.

Similar questions

4 replies
Question marked as Top-ranking reply

Dec 1, 2021 6:58 AM in response to Camelot

The code shown is the relevant part of the script, there is much more to it, the result of the script adds a line of data to a Numbers sheet. That is why it appears that I do nothing with the variables. I know Automator fails to execute the script because Automator ends with the green check and "Workflow completed" message and displays the input file in the results box, but no data added to the spreadsheet nor are any other messages displayed. If, after Automator completes and with out exiting, I click the AppleScript execute button, the script executes successfully and adds the information to the spreadsheet.


I have also tried a version of this script trying to use the file passed from the Preview "Extract PDF Data" step, and the script fails to run, with the same results, Automator completes successfully but no update to the spreadsheet.

Nov 30, 2021 10:36 AM in response to PT701

When you say it doesn't execute, how are you determining this? There's nothing in the script that would have any obvious action.


Ostensibly, your script defines a couple of variables based on whether a specific file exists on your desktop:


if exists file File1 then
    set FileName to File1 as string
    set NumberFile to "File1.numbers"
    set subFolder to "D1:"
    set sourceName to "File1.pdf"
else....


You don't do anything with the variables NumberFile, subFolder or sourceName, so it isn't clear what you're doing.


There are, however, a couple of errors in your script that could have an impact.


First, your catch in case neither file exist - you post a dialog to inform the user Input File Not Found, but then the script goes ahead and tries to open the file anyway. If you expect the script to bail at this point, you need to add a return statement.


Additionally, you say:


> I have initially tried to run this script using the inFile parameter to set the file name


Without seeing what the previous action is doing, it's impossible to tell if this is valid or not. I don't know what text you are expecting to be extracted from the PDF, nor whether that is something that the script would interpret as a file path.


So other than moving the file to the trash (which I suppose could indicate the script ran), it's not clear what you expect this script to do, nor what it isn't doing that has you coming here.

Dec 1, 2021 9:43 AM in response to PT701

> I know Automator fails to execute the script because Automator ends with the green check and "Workflow completed" message


On the contrary, the script DID execute - that's why you get the 'completed' message and the green checkmark.


The issue is that it's not doing what you want, which implies some kind of logic failure (e.g. an if statement that returns false and therefore skips some part of the flow).


As such, the flaw is probably in the piece of script that you omitted, which makes debugging this much harder :)


You probably need to show the full script so that the flow can be traced.

Applescript in Automator fails to execute

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.