Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

365
Views
How can I get an input folder and its files using Javacript for Automator?

I am writing an automator workflow to work with files and folders. I’m writing it in JavaScript as I’m more familiar with it.

I would like to receive a folder, and get the folder’s name as well as the files inside.

Here is roughly what I have tried:

  1. Window receives current folders in Finder (I’m only interested in the first and only folder)

  2. Get Folder Contents

  3. JavaScript:

    function run(input,parameters) {
        var files = [];
        for(let file of input) files.push(file.toString().replace(/.*\//,''));
        //  etc
    }
    

This works, but I don’t have the folder name. Using this, I get the full path name of each file, which is why I run it through the replace() method.

If I omit step 2 above, I get the folder, but I don’t know how to access the contents of the folder.

I can fake the folder by getting the first file and stripping off the file name, but I wonder whether there is a more direct approach to getting both the folder and its contents.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I’ve got it working. In case anybody has a similar question:

//  Window receives current folders in Finder

var app = Application.currentApplication()
app.includeStandardAdditions = true

function run(input, parameters) {
    let directory = input.toString();
    var directoryItems = app.listFolder(directory, { invisibles: false })
    var files = [];

    for(let file of directoryItems) files.push(file.toString().replace(/.*\//,'')) ;

    //  etc
}

I don’t include the Get Folder Contents step, but iterate through the folder using app.listFolder() instead. The replace() method is to trim off everything up to the last slash, giving the file’s base name.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!