Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose setting isn't working #30

Closed
vaxinc opened this issue Jan 9, 2021 · 9 comments
Closed

Verbose setting isn't working #30

vaxinc opened this issue Jan 9, 2021 · 9 comments
Labels

Comments

@vaxinc
Copy link

vaxinc commented Jan 9, 2021

This work
(async () => { console.log(await tasklist()); })();
This doesn't
(async () => { console.log(await tasklist({verbose: true})); })();

No errors, just nothing. It seems as if the async function assigned to this task, completely stop working or is just running in a loop that cant be resolved. Is there something im missing, like some setting tweaking i need to do beforehand, or something completely different?

@MarkTiedemann
Copy link
Contributor

@vaxinc As written in the README.md, verbose is slow.

Warning: Using the verbose option may have a considerable performance impact (See: #6).

On my machine, for example, it taskes almost 6 seconds to print the verbose tasklist.

const tasklist = require("tasklist");

(async () => {
  console.time();
  console.log(await tasklist({ verbose: true }));
  console.timeEnd();
})();
default: 5.833s

@vaxinc
Copy link
Author

vaxinc commented Jan 9, 2021

@vaxinc As written in the README.md, verbose is slow.

Warning: Using the verbose option may have a considerable performance impact (See: #6).

On my machine, for example, it taskes almost 6 seconds to print the verbose tasklist.

const tasklist = require("tasklist");

(async () => {
  console.time();
  console.log(await tasklist({ verbose: true }));
  console.timeEnd();
})();
default: 5.833s

i see, apologize for the inconvience. Apparently i either have a slow machine or too many tasks open
default: 69839.55395507812 ms

Is there a way to optimize this? Like only look for tasks with a certain imagename?

@vaxinc
Copy link
Author

vaxinc commented Jan 9, 2021

`(async () => {
console.log(console.time());
var taskArr;
taskArr = await tasklist();
var SpotifyPid;
for(var i = 0; i < taskArr.length; i++){
if(taskArr[i].imageName == "Spotify.exe"){
SpotifyPid = taskArr[i].pid;
}
}
var SpotifyTask = await tasklist({verbose: true, pid: SpotifyPid}) //This doesn't work btw
console.log(SpotifyTask.windowTitle);
console.log(console.timeEnd());

})();`

Something like this perhaps, dont know why the code markup wont work

@MarkTiedemann
Copy link
Contributor

Apparently i either have a slow machine or too many tasks open default: 69839.55395507812 ms

@vaxinc tasklist.exe is quite slow in general. (Hence, I created fastlist.exe. Alternatively, wmic process may be faster on your machine, too (e.g. wmic.exe process get name,processid,parentprocessid).).

What's your use-case? Maybe I'm able to help if I know your requirements.

@vaxinc
Copy link
Author

vaxinc commented Jan 9, 2021

Apparently i either have a slow machine or too many tasks open default: 69839.55395507812 ms

@vaxinc tasklist.exe is quite slow in general. (Hence, I created fastlist.exe. Alternatively, wmic process may be faster on your machine, too (e.g. wmic.exe process get name,processid,parentprocessid).).

What's your use-case? Maybe I'm able to help if I know your requirements.

An electronjs application that uses genius.com's api to retrieve lyrics for the current playing spotify song. I've developed this exact same app through pygame, so i know the procedure to it. The thing about spotify is that whenever you are playing a song, the windowTitle will change to the song name, so therefore the most efficient way to get the current playing song on spotify would be to look for the spotify.exe task and retrieve it's title. I'll look into fastlist though, thanks

@MarkTiedemann
Copy link
Contributor

MarkTiedemann commented Jan 9, 2021

How about?

powershell -c "get-process -name spotify | where { $_.mainwindowtitle } | select -expand mainwindowtitle"

e.g.

const child_process = require("child_process");

function current_spotify_song() {
    return new Promise(resolve => {
        child_process.execFile("powershell.exe", [ "-c", "get-process -name spotify | where { $_.mainwindowtitle } | select -expand mainwindowtitle" ], (err, stderr) => {
            if (err) {
                // No permission to execute powershell
                return resolve(null);
            }
            let song = stderr.trim();
            if (!song.includes(" - ")) {
                // Spotify is open but there's no song playing
                return resolve(null);
            }
            resolve(song);
        });
    });
}

(async () => {
    console.log(await current_spotify_song());
})();

@MarkTiedemann
Copy link
Contributor

Actually, on second thought, tasklist should work fine, too. You will need a filter, though.

const tasklist = require("tasklist");

(async () => {
    let spotify_tasks = await tasklist({ verbose: true, filter: ["imagename eq spotify.exe"] });
    console.log(spotify_tasks);
})();

Does this have acceptable performance on your machine?

@vaxinc
Copy link
Author

vaxinc commented Jan 9, 2021

Actually, on second thought, tasklist should work fine, too. You will need a filter, though.

const tasklist = require("tasklist");

(async () => {
    let spotify_tasks = await tasklist({ verbose: true, filter: ["imagename eq spotify.exe"] });
    console.log(spotify_tasks);
})();

Does this have acceptable performance on your machine?

YES! very much, under 500ms! Thank you man

@vaxinc vaxinc closed this as completed Jan 9, 2021
@MarkTiedemann
Copy link
Contributor

Glad this worked for you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants