Multiple "Run AppleScript" actions cause workflow to fail

I am running into the following error in Automator when attempting to run multiple AppleScript actions, the 2nd and 3rd setting variables:

-[NSAppleEventDescriptor fileSystemRepresentation]: unrecognized selector sent to instance 0x6000009e51a0

As long as there is only one of the second or third “Run AppleScript” actions in the workflow (either one), it runs successfully. So it does not seem to be an issue with the content of either AppleScript.

The first AppleScript is merely to get an “Ask For Text” window to appear:


The next AppleScript (first one to prompt to get a variable) is:

-- a sample AppleScript program to prompt a user to select an item from a list

-- display a dialog to prompt the user to select a dayname from a list
set myDay to {"m", "t", "w", "h", "f", "s", "x"}

-- get the file the user selected from the list
set selectedDay to item 1 of {choose from list myDay}

and the third one, again to set a variable:

set chosenTime to choose from list {"today", "yesterday"}

set UserChoice to item 1 of chosenTime
set myTime to "" -- good practice to initialise a variable
if UserChoice is "today" then
	set myTime to "0"
else if UserChoice is "yesterday" then
	set myTime to "1"
end if

I can run with AppleScript 1 and 2, or AppleScript 1 and 3, and no errors. But if I run with 1, 2 & 3 I get the error.

Here is the shell script in case that helps:

DATE=$(date -v-$3d +“%Y-%m-%d”)
echo -e “$DATE $2 | $FILE_CONTENT \n___\n” | cat - /Users/George/Dropbox/Notes/|\•\ recap_test\ “$DATE”.txt > /tmp/tempfile && mv /tmp/tempfile /Users/George/Dropbox/Notes/|\•\ recap_test\ “$DATE”.txt
echo -e “$DATE $2 | $FILE_CONTENT \n___\n” | cat - /Users/George/Dropbox/Notes/|\•\ 1journal_test.txt > /tmp/tempfile && mv /tmp/tempfile /Users/George/Dropbox/Notes/|\•\ 1journal_test.txt[/format]

Ultimately, I am trying to modify the date variable in the shell script using the variable from the 3rd AppleScript (the idea being to subtract the value in the variable from the 3rd AppleScript).


The error’s an Objective-C one, so presumably it’s being thrown by Automator itself.

Presumably is is to bring the Automator workflow to the front.

That last line should be:

set selectedDay to (choose from list myDay) -- Parentheses, NOT braces.
if (selectedDay is false) then error number -128 -- 'choose from list' uniquely returns 'false' when its "Cancel" button's clicked.
set selectedDay to item 1 of selectedDay

The result returned from the script, which in this case happens to be the result of the ‘set’ command in the last line, goes through as the input to the next action in the workflow. If the next action doesn’t use this result itself, you have to use the “Set Value of Variable” action at this point to remember the value until it’s needed. It can be retrieved later in the workflow with the “Get Value of Variable” action. The AppleScript variables themselves aren’t remembered from script to script. The values have to be assigned to Automator variables if they’re needed later. Similarly with the results of any actions between the script actions.

There’s no mention of a shell script in your post before this point. :confused: