2

I'ld like to get all open applications on mac. I'm try to code below, but this code get all open process on mac. I need only the applications that show on command+tab. Tks!

    try {
        String line;
        String[] cmd = {"/bin/sh", "-c", "ps -ef | grep .app | awk '{print $2}'"};
        Process p = Runtime.getRuntime().exec(cmd);

        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((line = input.readLine()) != null) {
            list.add(line);
        }
        input.close();
    } catch (Exception err) {
        err.printStackTrace();
    }

0 Answers0