actiona
actiona copied to clipboard
How can i find a window by pid ?
Hello, i'm trying to find a window by pid but it seems the program doesn't find the window.
I'm executing a detached command, in advanced -> output parameters i wrote the variable p1.
Then i use the action Window and in the input parameters -> Window title. On this field i'm writing this code:
var processHDL= new ProcessHandle(p1);
var windows = Window.find({
process: processHDL
});
Any idea ? Example attached.
Hi, there is one issue with your script: the Window title
field of the Window
action was set to Text
and not Code
, but it contains Javascript.
You're right, i switch Text to Code but it seems to be the same. It throw an exception because cannot find the window, this exception is configured like this:
goto line 3
The line 3 in the script is a code with this content:
Console.print("pid: " + p1);
So, the main problem is that the window cannot be find by pid. Although the pid in the variable p1
is ok.
I tried the next code but it does not works too.
var windows = Window.find({
processId: p1
});
Is there another alternative to do this? Thanks.
I think the other issue is that your script needs to return a window title. You could write something like that:
var processHDL= new ProcessHandle(p1);
var windows = Window.find({
process: processHDL
});
if(windows.length > 0) {
return windows[0];
} else {
return "Invalid window";
}
I found out the way to do this with your script. I had to remove the return
due to it throw an invalid statement at execution and i added the method title()
in the end of windows[0]
. The result is this:
var processHDL= new ProcessHandle(p1);
var windows = Window.find({
process: processHDL
});
if(windows.length > 0) {
windows[0].title();
} else {
"Invalid window";
}
Thank you so much.
additionally, is there a possibility to implement into a window action the option to find the program by pid or process name instead of only window title?
I found out the way to do this with your script. I had to remove the
return
due to it throw an invalid statement at execution and i added the methodtitle()
in the end ofwindows[0]
.
Ah yes, sorry. I had to rewrite this code after having tested it.
additionally, is there a possibility to implement into a window action the option to find the program by pid or process name instead of only window title?
Yes, that would make sense. Thanks for the idea.