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

213
Visualizações
electronJS / Detect if foreign app is running (MacOS) (Sandbox) (MAS)

Is it possible to detect in electronJS if are specific Apps are running on MacOS?

I want to check, if the Mail.app is open and its important, that the code works in Mac Apple Store (MAS) in Sandbox Mode.

In AppKit it is possible with var runningApplications: [NSRunningApplication] { get } https://developer.apple.com/documentation/appkit/nsworkspace/1534059-runningapplications

I have wrote an code, which is working, but not in Sandbox, terminal commands are not possible:

 import { exec } from "child_process";
 ...

 isRunning(query: string): Promise<unknown> {
    return new Promise((resolve, reject) => {
        const cmd = `ps aux | grep "${query}" | grep -v grep`;


        exec(cmd, (err, stdout, stderr) => {

            if (stderr) {
                reject(stderr);
                return false;
            }

            const lines = stdout.split("\n");
            let active = null;
            let pid = null;

            for (let index = 0; index < lines.length; index++) {
                const line = lines[index];

                if (
                    line.indexOf(query) !== -1 &&
                    line.indexOf(USERNAME) !== -1

                ) {
                    active = line;
                    break;
                }
            }

            if (active) {
                const activeData = active.replace(/(\s+)/g, '\t').split('\t');
                pid = activeData.length > 2 ? activeData[1] : null;
            }

            resolve(pid);
        });
    });
}

this.isRunning('Mail.app/Contents/MacOS/Mail').then(pid => {
    if (pid) {
       // kill the app? 😉 
    } else {
        resolve(null);
    }
}, reject);

Has anyone a better solution for electronJS which works in MAS Sandbox?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I found a solution for it:

const script = `
if application "Mail" is running then
    copy "true" to stdout
else
    copy "false" to stdout
end if
`;

exec(`osascript -e '${script}'`,  (err, stdout, stderr) => {
    if (stderr) {console.log("error", stderr); return;}

    console.log("stdout", stdout);
});
about 4 years ago · Santiago Gelvez 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