Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

366
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda