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

254
Visualizações
How can I copy text to the clipboard in an Automator JavaScript?

I am writing a simple Automator script in JavaScript (because I’m much more productive in JavaScript). For testing purposes, I simply eval() the input.

The script is:


//  Workflow receives current text in any application

function run(input, parameters) {
    //  1+2*3
    
    var app = Application.currentApplication()
    app.includeStandardAdditions = true
    
//  app.displayDialog(input)
//  app.displayDialog(input[0])

    result = eval(input[0]) || 0;
    
    app.displayDialog(result)
    app.setTheClipboardTo(result)
    
    return result
}

//  Copy to Clipboard

I would like to get the result onto the clipboard. As you see above, I have applied the setTheClipboardTo() function.

The Workflow receives the current text.

I have also added the Copy to Clipboard action to the end.

I have tried with or without the setTheClipboardTo() function, and with or without the Copy to Clipboard action. The displayed message has the correct result, but I can’t get it to the clipboard.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I don’t know what I did wrong before, except possibly adding the action at the end. Here is a version that works:

//  Workflow receives current text in any application
//  Replaces Selection

function run(input, parameters) {
    //  1*2*3*4*5*6+7-8-9
    //  1 2 3
    
    var app = Application.currentApplication();
    app.includeStandardAdditions = true;
    
    //  Filter for eval()
        expression = input[0].replace(/[^0-9 +\-*\/÷×()]/g,'?')

    try {
        result = eval(input[0])*1;
    } catch(e) {
        result = 0
    }
    
    app.setTheClipboardTo(result.toString())
    
    return result
}
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