I have an automator workflow which works fine except for a part of it - applescript.

This is how the workflow goes -

Run applescript (this part works fine) -

on run {input, parameters}

    tell application "Mail" to set theMessageText to content of (get first message of inbox)
    set x to text ((offset of "9" in theMessageText) + 2) thru ((offset of " " in theMessageText) - 1) of theMessageText
end run

Set value for variable (The name of the variable is 'number')

Get value for variable (I have made sure that this receives no direct input from previous actions. I am calling the variable 'number' here and I have duplicated this process 2 more times to call 2 more variables)

Run Applescript (This is the code I have problem with) -

on run {input, parameters}
    set cat to first item of input
    set x to second item of input
    set o to third item of input
    tell application "Contacts"
        set thePerson to make new person with properties {first name:"Testing", last name:"Auto"}
        make new phone at end of phones of thePerson with properties {label:"Main", value:x}
        repeat with z from 1 to o
            set a to item z of cat
            add thePerson to group a
        end repeat
    end tell
end run

The error shown here is "Syntax Error - Can’t get item 2. Invalid index".

The point of the workflow is to get some contact details from an email and add them as a contact in address book (This isn't the full workflow as it is a fairly big one. I have shown only the relevant actions).

I would be grateful for any help.

1 Answer 1


The values you set before are not given via the inputparameter. As long as you run your Automator Workflow as an Automator Workflow and not as an Application or Service, you can access your formerly set variables using the following:

tell application "Automator"
    set cat to value of variable "NameOfFirstVariable" of front workflow
    set x to value of variable "NameOfSecondVariable" of front workflow
    set o to value of variable "NameOfThirdVariable" of front workflow
end tell

inside your "Run Applescript" action.

Greetings, Michael / Hamburg

  • I tried this but I get the following error "Can’t get item 2 of {3}". The problem seems to be in retrieving the second variable. The "Get value of Variable" action seems to be working fine. Every time I run the program, after the error dialog box, "item z" part of the code is highlighted. Any idea what is happening over here? Thanks for the help @ShooTerKo
    – Samyak
    Nov 22, 2014 at 10:56
  • You try set a to item z of cat inside repeat with z from 1 to o. It simply looks like o has a value greater than the amount of items in the list cat...
    – ShooTerKo
    Nov 25, 2014 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .