Saturday, July 11, 2020
  • Index
  •  » Automator
  •  » Multiple "Run AppleScript" actions cause workflow to fail

#1 2019-12-28 03:39:36 pm

gcoghill
Member
Registered: 2006-03-10
Posts: 6

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:

Applescript:

activate

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

Applescript:

--
-- 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:

Applescript:

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:

FILE_CONTENT=$1
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

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).

Last edited by gcoghill (2019-12-28 03:41:42 pm)

Offline

 

#2 2020-02-03 05:56:48 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5242

Re: Multiple "Run AppleScript" actions cause workflow to fail

gcoghill wrote:

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


Hi.

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

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

Applescript:

activate


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

Applescript:

--
-- 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}


That last line should be:

Applescript:

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.

Here is the shell script in case that helps:


There's no mention of a shell script in your post before this point.  hmm


NG

Offline

 
  • Index
  •  » Automator
  •  » Multiple "Run AppleScript" actions cause workflow to fail

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)