Home > Software engineering >  Use Automator App Variables as imput for Javascript action steps
Use Automator App Variables as imput for Javascript action steps

Time:02-11

I am trying to input the content of a variable generated with the Automator app onto the next action step, to define the value of a javascript script variable. Change the variable using javascript code and push the result further to the next action step. Then turn it back into an Automator variable, or update the one previously used as input. I am sure you will find it as a simple thing, but I couldn't find a way to get it working. This question might be silly, after all. Many thanks in advance. Check the screenshot of the Automator sequence of steps. Screenshot of the actions set in Automator App

function run(input) {
    
    var str = input;
var l1 = str.replace(/ /g, "_");
    str = l1;
var l2 = str.replace(/:/g, "-");

    return l2;
}

CodePudding user response:

The input to an Automator action is an array, so you will need to step through the array or convert/coerce to whatever class you are wanting to work with. In your posted script, the replace() method is for a string, so you are getting an error trying to use that method on the input array.

If you just want a single input item you can use input[0] to get the first item in the array, or input.join() to join the array items together.

  • Related