Force Firefox window to Focus on screen when...?

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Legalien
Posts: 67
Joined: Mon Feb 15, 2016 6:47 pm
Contact:

Force Firefox window to Focus on screen when...?

Post by Legalien » Tue Aug 13, 2019 12:19 am

So I doubt this is possible, but I'll ask anyway.

I use Windows 10 | Firefox Portable v55 | iMacros 8.9.7

Now, say I'm running 10 windows of Firefox. And iMacros are spinning and doing their thing 24/7. They windows are not minimized, but 1 is visible on the screen and the other 9 are "behind" it.

Multiple times per day each of the browsers will visit a specific site at some point, and this site is extremely slow if the Firefox window is not centered :(

Is there a way for me to force the Firefox to get centered/focused/visible on the screen whenever a certain domain is visited or a certain text appears?

It would be awesome if I could do this with iMacros, but if not, any ideas of how I can accomplish this?

Thanks :)
Buy Social Media Services - https://Socialesale.com
rstancuna
Posts: 23
Joined: Sun Jun 16, 2019 10:27 pm

Re: Force Firefox window to Focus on screen when...?

Post by rstancuna » Fri Aug 23, 2019 1:50 pm

You cannot do this with iMacros.
Does the window need to be focused or just visible? If it just needs to be visible, then you tile them and make an array with all.
If the window needs to be focused, you would need to use an outside program like AutoHotkey and set it to move through each window and activate it, add a delay then activate the next one and so on.
Waterfox 56.2, iMacros V8.9.7 on Windows
chivracq
Posts: 8722
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Force Firefox window to Focus on screen when...?

Post by chivracq » Fri Aug 23, 2019 5:16 pm

Legalien wrote:
Tue Aug 13, 2019 12:19 am
So I doubt this is possible, but I'll ask anyway.

I use

Code: Select all

Windows 10 | Firefox Portable v55 | iMacros 8.9.7
Now, say I'm running 10 windows of Firefox. And iMacros are spinning and doing their thing 24/7. They windows are not minimized, but 1 is visible on the screen and the other 9 are "behind" it.

Multiple times per day each of the browsers will visit a specific site at some point, and this site is extremely slow if the Firefox window is not centered :(

Is there a way for me to force the Firefox to get centered/focused/visible on the screen whenever a certain domain is visited or a certain text appears?

It would be awesome if I could do this with iMacros, but if not, any ideas of how I can accomplish this?

Thanks :)
rstancuna wrote:
Fri Aug 23, 2019 1:50 pm
You cannot do this with iMacros.
Does the window need to be focused or just visible? If it just needs to be visible, then you tile them and make an array with all.
If the window needs to be focused, you would need to use an outside program like AutoHotkey and set it to move through each window and activate it, add a delay then activate the next one and so on.

Hum, I'm not too "sure" about your "You cannot do this with iMacros.", @rstancuna... :twisted:

But OK, I had also done "a bit of Thinking", @Legalien, 10 days ago when you had opened your Thread but my Reply would have been a bit "long", and I didn't do it directly at that moment, and I kept postponing it...

But yep indeed, 'AHK' or 'AutoIT' was also my first Idea, like @rstancuna, started "directly" or from some mini-'.BAT' File, either through the 'External Application Buttons' FF Add-on or from a mini-'.js' Script (or from your main '.js' Script if your Script is already a '.js'), there is some Syntax that allows to launch directly any '.EXE' or '.BAT' File from pure JS that works in v8.9.7 for FF + FF55 (and the Browser doesn't "complain" about Security)...

Next to 'AHK' and 'AutoIT', I "discovered" recently another Tool that can also do the same, is 'AutoClicker', a bit buggy but "does the job", and even works with multiple Screens... 8)
It works with Coordinates, so you would need to "calibrate" it a bit, and to make sure you always launch your Script with the Browser Instance maximized, with the iMacros Side-Panel of always the same Width, Window/Screen Resolution always the same (and on the same Screen if you work with multiple Screens), but it works... 8)
And even iMacros 'PROMPT''s always come at exactly the same place on your Screen, and only depend for the Position of the 'OK'/'Cancel' Buttons on the Amount of Text in them, so that Position/Coordinates would be fixed...

Then in pure 'JS', there are some JS Commands/Methods to control and force the Focus of a Tab or Browser Instance.
'PROMPT' or 'alert()' are also able to force a Focus onto a specific Browser Instance..., if the User won't always be present to dismiss the 'PROMPT' manually, there is also some Syntax to conditionally trigger an 'alert()' (from '.iim') with 'URL GOTO=javascript' (or from a '.js' Script), and that Alert can possibly be automatically dismissed after a mini-while, still from the same Script and from JS also, or again some mini 'AHK'/'AutoIT'/'AutoClicker' Script could have been launched just before triggering the Alert/PROMPT to click it away...

And then comes I think the "best" Option, ah-ah...!: 8)
Launching an iMacros Script ('.iim' or '.js') from a Shortcut or '.BAT' File (from the Windows Task Scheduler) launches (also) the Browser (Profile) if it's not running already, but always brings that Browser (Profile) Instance in the OS-Focus, which is normal if the Browser was not running yet, but also if the Browser is already running, before eventually opening a New Tab where the Script will run.

=> And this "Focus-Behaviour" is interesting I would think, as you could then split your original Script into 2 parts, that when your Script arrives on that specific Site, the first part of your Script then "finishes" by launching a '.BAT' File that will launch in return the 2nd part of your original Script (in a separate Script thus) and that will trigger therefore the Focus-Behaviour I mentioned. 8)
It will also open a New Tab in your Browser Instance, but that's trivial to deal with if you don't want several Tabs open. (But seeing a 2nd Tab open in your Browser, "a bit later" when you check if your Script is still running or has finished running can also be "an easy Confirmation" that it all worked OK...)
("TAB T=0" doesn't "really" work, the 'TAG' Mode refuses to do anything on negative Tabs, the Script simply "glides" on the Page but doesn't do anything..., although I've never tried to combine it with a 'TAB CLOSEALLOTHERS' + force a "new" 'TAB T=1' which will automatically force the "current" Tab to become 'TAB_1'...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
rstancuna
Posts: 23
Joined: Sun Jun 16, 2019 10:27 pm

Re: Force Firefox window to Focus on screen when...?

Post by rstancuna » Fri Aug 23, 2019 7:24 pm

chivracq wrote:
Fri Aug 23, 2019 5:16 pm
Then in pure 'JS', there are some JS Commands/Methods to control and force the Focus of a Tab or Browser Instance.
'PROMPT' or 'alert()' are also able to force a Focus onto a specific Browser Instance..., if the User won't always be present to dismiss the 'PROMPT' manually, there is also some Syntax to conditionally trigger an 'alert()' (from '.iim') with 'URL GOTO=javascript' (or from a '.js' Script), and that Alert can possibly be automatically dismissed after a mini-while, still from the same Script and from JS also, or again some mini 'AHK'/'AutoIT'/'AutoClicker' Script could have been launched just before triggering the Alert/PROMPT to click it away...
When you run a PROMPT iim command or alert()/prompt()/confirm() js command, the window gets notified (button flashing) but not focused. It would be a huge security risk to steal focus from any other open window when those commands are called and that's why it doesn't even work. So if firefox profile 7 will run one of those commands and you have profile 1 in focus, it will never steal the focus from 1 to 7.
chivracq wrote:
Fri Aug 23, 2019 5:16 pm
And then comes I think the "best" Option, ah-ah...!: 8)
Launching an iMacros Script ('.iim' or '.js') from a Shortcut or '.BAT' File (from the Windows Task Scheduler) launches (also) the Browser (Profile) if it's not running already, but always brings that Browser (Profile) Instance in the OS-Focus, which is normal if the Browser was not running yet, but also if the Browser is already running, before eventually opening a New Tab where the Script will run.
=> And this "Focus-Behaviour" is interesting I would think, as you could then split your original Script into 2 parts, that when your Script arrives on that specific Site, the first part of your Script then "finishes" by launching a '.BAT' File that will launch in return the 2nd part of your original Script (in a separate Script thus) and that will trigger therefore the Focus-Behaviour I mentioned. 8)
I did this long ago with some of my macros, it's an good workaround. I ended up combining different programs and in my opinion using AHK will give more utility than closing and opening browser with ".bat" files.
chivracq wrote:
Fri Aug 23, 2019 5:16 pm
It will also open a New Tab in your Browser Instance, but that's trivial to deal with if you don't want several Tabs open. (But seeing a 2nd Tab open in your Browser, "a bit later" when you check if your Script is still running or has finished running can also be "an easy Confirmation" that it all worked OK...)
("TAB T=0" doesn't "really" work, the 'TAG' Mode refuses to do anything on negative Tabs, the Script simply "glides" on the Page but doesn't do anything..., although I've never tried to combine it with a 'TAB CLOSEALLOTHERS' + force a "new" 'TAB T=1' which will automatically force the "current" Tab to become 'TAB_1'...)
Could always use "TAB CLOSEALLOTHERS" and then "TAB CLOSE" right after and your current tab will be TAB 1 .
Waterfox 56.2, iMacros V8.9.7 on Windows
chivracq
Posts: 8722
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Force Firefox window to Focus on screen when...?

Post by chivracq » Fri Aug 23, 2019 9:14 pm

Hum..., interesting "Discussion" @rstancuna, and nice to see that you are a pretty "Advanced" User, ah-ah...! Always good for the Forum... 8)
rstancuna wrote:
Fri Aug 23, 2019 7:24 pm
chivracq wrote:
Fri Aug 23, 2019 5:16 pm
Then in pure 'JS', there are some JS Commands/Methods to control and force the Focus of a Tab or Browser Instance.
'PROMPT' or 'alert()' are also able to force a Focus onto a specific Browser Instance..., if the User won't always be present to dismiss the 'PROMPT' manually, there is also some Syntax to conditionally trigger an 'alert()' (from '.iim') with 'URL GOTO=javascript' (or from a '.js' Script), and that Alert can possibly be automatically dismissed after a mini-while, still from the same Script and from JS also, or again some mini 'AHK'/'AutoIT'/'AutoClicker' Script could have been launched just before triggering the Alert/PROMPT to click it away...
When you run a PROMPT iim command or alert()/prompt()/confirm() js command, the window gets notified (button flashing) but not focused. It would be a huge security risk to steal focus from any other open window when those commands are called and that's why it doesn't even work. So if firefox profile 7 will run one of those commands and you have profile 1 in focus, it will never steal the focus from 1 to 7.
Hum, I'm not sure about "huge security risk", well, I agree actually, and I guess the Behaviour you describe about FF with Profiles 1 and 7 is indeed maybe "correct" about "plain" FF (I only have 1 FF Profile), but I use Pale Moon (with 3 Profiles) as my "Prod" Env. for iMacros, and I have the "Feeling" that PM is a bit more "aggressive" than FF concerning Focus and '.iim' 'PROMPT''s, because it has indeed happened to me many-many times, that I have 1-2-3 Script(s) running in 1 or 2 PM Profile(s), while manually typing a Post on the Forum for example, in my 3rd Profile, and if at any point any Script from the 2 other Profiles triggered a 'PROMPT', that PM Instance and its 'PROMPT' completely steals the Focus from what I was doing "manually" on the Forum in the 3rd Profile...

But I also "work" with 3 Screens, so I always have "a lot" visible on my 2 "secondary"/external Screens, so the Visible/Focus/Active Priority and Behaviour at the OS-Level (Win10_x64) might be a bit different than when you "only" have 1 Screen... I don't really know, I never really did any Testing about that, but I just know that if any of my Scripts running at that time has or might have triggered a 'PROMPT', I need to check first where my Cursor/Mouse is before hitting a Keyboard 'Enter' for example, or chances are that 'Enter' will simply dismiss that one Display-'PROMPT' on my 2nd or 3rd Screen instead of adding a Hard-Return in this current Post for the Forum, ah-ah...!

>>>
rstancuna wrote:
Fri Aug 23, 2019 7:24 pm
chivracq wrote:
Fri Aug 23, 2019 5:16 pm
And then comes I think the "best" Option, ah-ah...!: 8)
Launching an iMacros Script ('.iim' or '.js') from a Shortcut or '.BAT' File (from the Windows Task Scheduler) launches (also) the Browser (Profile) if it's not running already, but always brings that Browser (Profile) Instance in the OS-Focus, which is normal if the Browser was not running yet, but also if the Browser is already running, before eventually opening a New Tab where the Script will run.
=> And this "Focus-Behaviour" is interesting I would think, as you could then split your original Script into 2 parts, that when your Script arrives on that specific Site, the first part of your Script then "finishes" by launching a '.BAT' File that will launch in return the 2nd part of your original Script (in a separate Script thus) and that will trigger therefore the Focus-Behaviour I mentioned. 8)
I did this long ago with some of my macros, it's an good workaround. I ended up combining different programs and in my opinion using AHK will give more utility than closing and opening browser with ".bat" files.
I didn't mean closing any Browser, only opening, and not even, as in this Case for @OP, the same Browser/Profile would already be open for the 1st part of the whole Script.

But closing+opening (in this Order) (from a '.BAT' Fie) can indeed be "useful" for Scripts that need to run 24/7, especially on FF, ah-ah...! (... as FF usually starts getting slower and slower after a few hours, because of Memory Leaks etc..., main Reason why I actually use PM myself...).

But 'AHK' can indeed be very-very powerful, it's only always a bit "not very straightforward" for iMacros and 'AHK' to "communicate" with each other, and in both Directions...

>>>
rstancuna wrote:
Fri Aug 23, 2019 7:24 pm
chivracq wrote:
Fri Aug 23, 2019 5:16 pm
It will also open a New Tab in your Browser Instance, but that's trivial to deal with if you don't want several Tabs open. (But seeing a 2nd Tab open in your Browser, "a bit later" when you check if your Script is still running or has finished running can also be "an easy Confirmation" that it all worked OK...)
("TAB T=0" doesn't "really" work, the 'TAG' Mode refuses to do anything on negative Tabs, the Script simply "glides" on the Page but doesn't do anything..., although I've never tried to combine it with a 'TAB CLOSEALLOTHERS' + force a "new" 'TAB T=1' which will automatically force the "current" Tab to become 'TAB_1'...)
Could always use "TAB CLOSEALLOTHERS" and then "TAB CLOSE" right after and your current tab will be TAB 1 .
Euh...!?, the 'TAB CLOSE' after a 'TAB CLOSEALLOTHERS' will simply close the Browser Instance, I would think...! :shock:
Ah-ah-ah...!, hum, depends indeed on some 'about:config' Setting, OK, that's possible to prevent then indeed... But I have that Setting on "Allow" myself... Hum..., I once did some Testing about that..., in this interesting Thread... :wink: (Well, the "interesting Thread" is the Link in my Post...)

>>>

And arrgghhh, I knew I had been a bit more "productive" and "creative" 10 days ago when I had done my original "Thinking", I had thought indeed about several other "Ways" than the few ones I mentioned this "Afternoon", but..., oops, I have some Friend coming over right now, so I prefer to post my Reply already...

[=> 'Powershell' + 'Win^m' + 'Alt^Tab' (x2) or + 'Alt^Shift*Tab' from 'EVENT' Mode + enumerate all running Apps and Processes from 'ps'...]
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
rstancuna
Posts: 23
Joined: Sun Jun 16, 2019 10:27 pm

Re: Force Firefox window to Focus on screen when...?

Post by rstancuna » Sat Aug 24, 2019 10:49 am

chivracq wrote:
Fri Aug 23, 2019 9:14 pm
Hum, I'm not sure about "huge security risk", well, I agree actually, and I guess the Behaviour you describe about FF with Profiles 1 and 7 is indeed maybe "correct" about "plain" FF (I only have 1 FF Profile), but I use Pale Moon (with 3 Profiles) as my "Prod" Env. for iMacros, and I have the "Feeling" that PM is a bit more "aggressive" than FF concerning Focus and '.iim' 'PROMPT''s, because it has indeed happened to me many-many times, that I have 1-2-3 Script(s) running in 1 or 2 PM Profile(s), while manually typing a Post on the Forum for example, in my 3rd Profile, and if at any point any Script from the 2 other Profiles triggered a 'PROMPT', that PM Instance and its 'PROMPT' completely steals the Focus from what I was doing "manually" on the Forum in the 3rd Profile...

But I also "work" with 3 Screens, so I always have "a lot" visible on my 2 "secondary"/external Screens, so the Visible/Focus/Active Priority and Behaviour at the OS-Level (Win10_x64) might be a bit different than when you "only" have 1 Screen... I don't really know, I never really did any Testing about that, but I just know that if any of my Scripts running at that time has or might have triggered a 'PROMPT', I need to check first where my Cursor/Mouse is before hitting a Keyboard 'Enter' for example, or chances are that 'Enter' will simply dismiss that one Display-'PROMPT' on my 2nd or 3rd Screen instead of adding a Hard-Return in this current Post for the Forum, ah-ah...!
Never tested Pale Moon but on Firefox and Waterfox they can't steal focus. I'm glad they can't since i usually use alert() for debug.
chivracq wrote:
Fri Aug 23, 2019 9:14 pm
I didn't mean closing any Browser, only opening, and not even, as in this Case for @OP, the same Browser/Profile would already be open for the 1st part of the whole Script.

But closing+opening (in this Order) (from a '.BAT' Fie) can indeed be "useful" for Scripts that need to run 24/7, especially on FF, ah-ah...! (... as FF usually starts getting slower and slower after a few hours, because of Memory Leaks etc..., main Reason why I actually use PM myself...).
What you were thinking, only works with the default profile. So let's say 1 is default.

Code: Select all

C:\Program Files\Mozilla Firefox\firefox.exe https://google.com
This will focus the default profile and open a new tab with that url. Ofcource it could be a js macro that will go to that URL and do all the magic.

Code: Select all

C:\Program Files\Mozilla Firefox\firefox.exe -P "7" -no-remote https://google.com
This won't open a new tab with that url in profile 7, instead it actually runs the new profile instance with that url. So if that profile is already open then you will be prompted to close the profile before continuing, unless Pale Moon is different here as well.

Indeed the memory leaks are a problem but from what I've seen it depends on the websites that you visit since they all save cache and cookies + ofcource history. To bypass this problem I've set all profiles to use Custom settings for history, have Always use private browsing mode enabled, Accept cookies from websites enabled (many of the ones I use will not work or work partially unless cookies are saved...) and Accept third-party cookies and Keep until I close. Also, all profiles have 0 history, cache and cookies to begin with.
You will always be logged out of websites but you can login from the macro or just manually login first then run macro.
chivracq wrote:
Fri Aug 23, 2019 9:14 pm
Euh...!?, the 'TAB CLOSE' after a 'TAB CLOSEALLOTHERS' will simply close the Browser Instance, I would think...! :shock:
Ah-ah-ah...!, hum, depends indeed on some 'about:config' Setting, OK, that's possible to prevent then indeed... But I have that Setting on "Allow" myself... Hum..., I once did some Testing about that..., in this interesting Thread... :wink: (Well, the "interesting Thread" is the Link in my Post...)
Indeed, "browser.tabs.closeWindowWithLastTab" from about:config will need to be set to false. Been having it as false for years, forgot it's actually set as true initially.
Waterfox 56.2, iMacros V8.9.7 on Windows
Legalien
Posts: 67
Joined: Mon Feb 15, 2016 6:47 pm
Contact:

Re: Force Firefox window to Focus on screen when...?

Post by Legalien » Fri Sep 06, 2019 11:21 pm

Wow you guys had a proper discussion here. Sorry I didn't reply sooner, I just saw it.

Well, a few things. I don't care much about security, as long as everything works. I disable all security and disable windows antivirus/defender/firewall crap and not install any antivirus. Like, it doesn't matter. I know what to do and not do on the internet of things, all my important files are on external hard drives which are disconnected from my machines, it's all good (hackers of the interwebs, please don't take this as a challenge. Thank you :D )

I use Firefox Portables by the way. So in my operation there are Firefox browsers/instances, but not really Firefox profiles as traditionally thought of where you create multiple profiles on the same Firefox.

So I solved this actually. I paid a guy on Fiverr $10,000 dollars!!! ok maybe it was more like $20 bucks and he created (chivracq mentioned it) a little script with AutoIt that centers a window when a certain keyword appears on the title of the tab/browser. It works great :)
Buy Social Media Services - https://Socialesale.com
chivracq
Posts: 8722
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Force Firefox window to Focus on screen when...?

Post by chivracq » Fri Sep 06, 2019 11:50 pm

Legalien wrote:
Fri Sep 06, 2019 11:21 pm
Wow you guys had a proper discussion here. Sorry I didn't reply sooner, I just saw it.

Well, a few things. I don't care much about security, as long as everything works. I disable all security and disable windows antivirus/defender/firewall crap and not install any antivirus. Like, it doesn't matter. I know what to do and not do on the internet of things, all my important files are on external hard drives which are disconnected from my machines, it's all good (hackers of the interwebs, please don't take this as a challenge. Thank you :D )

I use Firefox Portables by the way. So in my operation there are Firefox browsers/instances, but not really Firefox profiles as traditionally thought of where you create multiple profiles on the same Firefox.

So I solved this actually. I paid a guy on Fiverr $10,000 dollars!!! ok maybe it was more like $20 bucks and he created (chivracq mentioned it) a little script with AutoIt that centers a window when a certain keyword appears on the title of the tab/browser. It works great :)

Alright, Thanks for the Update...

And yep 'AHK' or 'AutoIT'' were indeed my first Ideas, when I had done some "Thinking", the first time... Nice to hear that it works indeed with 'AutoIT'... 8)

I'm just wondering how both Scripts (the iMacros one and the 'AutoIT' one) "connect" and "communicate" with each other, and if the iMacros Script is launching the 'AutoIT' Script when it is needed, or going to be needed, or if the 'AutoIT' Script is already running all the time and is kind of "listening"/"waiting" for that Keyword to appear...?

Would be nice btw if you could share that 'AutoIT' Script, it's a very nice and powerful Tool, that can often be combined with iMacros indeed, for Functionality that iMacros can't (really/easily) do, and we don't have many 'AutoIT' Sample Scripts on the Forum... And yours could be useful, with a "practical" Use, and would be a good Example... (And that might "motivate" me to play a bit with it, ah-ah...!, just like I also have 'AHK' installed already..., but I don't do much with it...) :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
rstancuna
Posts: 23
Joined: Sun Jun 16, 2019 10:27 pm

Re: Force Firefox window to Focus on screen when...?

Post by rstancuna » Mon Sep 09, 2019 12:30 pm

With AHK, you can do something like this:

Code: Select all

#SingleInstance, Force
SetTitleMatchMode, 2
DetectHiddenWindows, On

Loop{
	;if GetKeyState("F4","P") ;break out of loop if F4 is pressed
	;	Break
	WinActivate, Part_Of_The_Name
	sleep 500
}

^+t:: ;Ctrl+Shift+T
ExitApp
return
You can also set "SetTitleMatchMode RegEx" instead of 2 and "Part_Of_The_Name" will then be a AHK RegEx to match it. To stop it you would need to use Ctrl+Shift+T but this will kill the whole script, if you just want to exit the loop (maybe you have more commands that would like to be run after the loop is exited) then you can just uncomment the first 2 lines from inside the loop.
Waterfox 56.2, iMacros V8.9.7 on Windows
Legalien
Posts: 67
Joined: Mon Feb 15, 2016 6:47 pm
Contact:

Re: Force Firefox window to Focus on screen when...?

Post by Legalien » Thu Sep 12, 2019 11:41 am

chivracq wrote:
Fri Sep 06, 2019 11:50 pm
Legalien wrote:
Fri Sep 06, 2019 11:21 pm
Wow you guys had a proper discussion here. Sorry I didn't reply sooner, I just saw it.

Well, a few things. I don't care much about security, as long as everything works. I disable all security and disable windows antivirus/defender/firewall crap and not install any antivirus. Like, it doesn't matter. I know what to do and not do on the internet of things, all my important files are on external hard drives which are disconnected from my machines, it's all good (hackers of the interwebs, please don't take this as a challenge. Thank you :D )

I use Firefox Portables by the way. So in my operation there are Firefox browsers/instances, but not really Firefox profiles as traditionally thought of where you create multiple profiles on the same Firefox.

So I solved this actually. I paid a guy on Fiverr $10,000 dollars!!! ok maybe it was more like $20 bucks and he created (chivracq mentioned it) a little script with AutoIt that centers a window when a certain keyword appears on the title of the tab/browser. It works great :)

Alright, Thanks for the Update...

And yep 'AHK' or 'AutoIT'' were indeed my first Ideas, when I had done some "Thinking", the first time... Nice to hear that it works indeed with 'AutoIT'... 8)

I'm just wondering how both Scripts (the iMacros one and the 'AutoIT' one) "connect" and "communicate" with each other, and if the iMacros Script is launching the 'AutoIT' Script when it is needed, or going to be needed, or if the 'AutoIT' Script is already running all the time and is kind of "listening"/"waiting" for that Keyword to appear...?

Would be nice btw if you could share that 'AutoIT' Script, it's a very nice and powerful Tool, that can often be combined with iMacros indeed, for Functionality that iMacros can't (really/easily) do, and we don't have many 'AutoIT' Sample Scripts on the Forum... And yours could be useful, with a "practical" Use, and would be a good Example... (And that might "motivate" me to play a bit with it, ah-ah...!, just like I also have 'AHK' installed already..., but I don't do much with it...) :idea:
The iMacros and AutoIT thing don't communicate at all. The iMacros are doing what they're doing, and AutoIT monitors all the browsers at all times waiting for the keyword to appear, and when it does AutoIT centers that window immediately. A bit of a hassle really if I want to do something on one of my other PCs and I have 30 Firefoxes running and it keeps taking me away from what I'm doing ha ha :D

But it's all good, works great.

I wouldn't share the script publicly, but I would give it to you if you want it. And then you can do whatever you want with it :)

If you want it let me know by replying here or sending me a private message (if the forum has a private message function, I'm not sure). And as soon as I see it I'll send it to you.

Cheers :)
Buy Social Media Services - https://Socialesale.com
chivracq
Posts: 8722
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Force Firefox window to Focus on screen when...?

Post by chivracq » Fri Sep 13, 2019 1:24 am

Legalien wrote:
Thu Sep 12, 2019 11:41 am
The iMacros and AutoIT thing don't communicate at all. The iMacros are doing what they're doing, and AutoIT monitors all the browsers at all times waiting for the keyword to appear, and when it does AutoIT centers that window immediately. A bit of a hassle really if I want to do something on one of my other PCs and I have 30 Firefoxes running and it keeps taking me away from what I'm doing ha ha :D

But it's all good, works great.

I wouldn't share the script publicly, but I would give it to you if you want it. And then you can do whatever you want with it :)

If you want it let me know by replying here or sending me a private message (if the forum has a private message function, I'm not sure). And as soon as I see it I'll send it to you.

Cheers :)

Yep, that's what I thought about the "Communication" between the 2 Scripts...

Hum, 30 FF Instances running at the same time...! Hum..., OK, let me check your FCI, => v8.9.7 for FF, and on FF55 indeed...!
Hum, OK, I don't know what kind of "Super" Computer you have that can handle 30x FF's, even Portable, you would be much better using 'Pale Moon' I would think... One single FF Instance usually needs constantly 20% CPU and usually crashes 3h later, I don't know how you do it with 30x FF's, ah-ah...! :? :shock:

And maybe an Idea about all Focus Events to use a VM or VPS, but hum, iMacros running in a VM is actually known to "have Pb's" when a Window needs to be "visible", will probably be the same or even worse if that Window needs "the Focus", I'm not sure what "having the Focus" will "really" mean for your 'AutoIT' Script inside a VM, ah-ah...! Well, or to dedicate a separate Laptop/Desktop to those 30x FF's... :idea:

Yep, about your 'AutoIT' Script, I would be interested to have a mini-Look at it, just out of Curiosity, I'm not "planning" to do anything with it, ah-ah...!, and I don't need that Functionality for myself, (I think...!? :P ), but it might give me a few "Ideas" and motivate me a bit to do a bit of "playful" Experimenting with 'AutoIT', ah-ah...!
'>
You can send it by Mail to [My_Pseudo_on_the_Forum]@gmail.com, and/or if it's not too big, still use the "fake" Report way to communicate privately, only me and the Forum Admin (= @TechSup, and I'm the only Mod on the Forum) can see Reports, PM not enabled on the Forum, I don't know if there is a Size Limit for the Comment Field in Reports, I never "pushed" that Func, ah-ah...! (Grrr..., OK, I will have to test it now, re-grrrr...! :twisted: )
'>
Mail might be easier though..., some Formatting/Spacing/etc... might get lost in that Comment Field...
(Just give a "Descriptive"/Explanatory Subject Title to your Mail, I receive a lot of Mail, and I "won't know" your E-mail Address, but "iMacros + AutoIT" in it should already "do it", ah-ah...! :wink: Oh...!, and you were from Canada I think, if you are a French Canadian, you can even speak French in your Mail, ah-ah...! (I'm French-French myself, originally from "Mother-France", ah-ah...!, you know, that Country were they speak "proper" French, and like to guillotinate Kings for Fun, especially if they wear a Wig..., ah-ah...! :P ))

(And I had seen your Report about some other Thread of yours about the 'CLICK X/Y' Mode and Anti-Bot Detection on the Site with some L&P to access that Site... I haven't given it a Try/Look yet... (You will get a Notif when I close the Report after I logged to the Site, and I will post "stg" in the Thread of course...))

Did you maybe give a Try at @rstancuna's Script in 'AHK'...? He's also an Advanced User in iMacros, + Knowledgeable in 'AHK', could come in "handy" one day, you never know, ah-ah...! Might save you another 10 or 20 Bucks one day, ah-ah...! 8)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
User avatar
thecoder2012
Posts: 359
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: Force Firefox window to Focus on screen when...?

Post by thecoder2012 » Sun Sep 15, 2019 6:50 pm

Legalien wrote:
Tue Aug 13, 2019 12:19 am
Multiple times per day each of the browsers will visit a specific site at some point, and this site is extremely slow if the Firefox window is not centered :(
It's easy in iMacros for Firefox with v8.9.7 and a little Javascript.

Example in pure Javascript:

Code: Select all

window.screenX=((window.screen.availWidth/2)-(window.outerWidth/2));
window.screenY=((window.screen.availHeight/2)-(window.outerHeight/2));
If it's not as URL GOTO possible then as very small addon as XPI File with protocol handler api.
Legalien wrote:
Tue Aug 13, 2019 12:19 am
Is there a way for me to force the Firefox to get centered/focused/visible on the screen whenever a certain domain is visited or a certain text appears?
It would be awesome if I could do this with iMacros, but if not, any ideas of how I can accomplish this?
Focus/visible is tricky in my first tests.

But the fastest or easiest version is with powershell under Windows.

1. Powershell command:

Code: Select all

powershell -Command (New-Object -ComObject WScript.Shell).AppActivate((Get-Process firefox).MainWindowTitle)
Same for basilisk:

Code: Select all

powershell -Command (New-Object -ComObject WScript.Shell).AppActivate((Get-Process basilisk).MainWindowTitle)
Special case multi process software (e.g. waterfox):

Code: Select all

powershell -Command Get-Process waterfox
Then use the process id:

Code: Select all

powershell -Command (New-Object -ComObject WScript.Shell).AppActivate((Get-Process -Id 14700).MainWindowTitle)
2. With iMacros and Javascript:

Code: Select all

const FileFactory = new Components.Constructor("@mozilla.org/file/local;1","nsILocalFile","initWithPath");
var str_LocalProgram = "C:\\Windows\\system32\\cmd.exe";
var obj_Program = new FileFactory(str_LocalProgram); 
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(obj_Program);
var args = ["/C",'powershell -Command (New-Object -ComObject WScript.Shell).AppActivate((Get-Process firefox).MainWindowTitle)'];
process.run(true, args, args.length);
Tested with iMacros v8.9.7, Win8.1 (64-Bit) and Basilisk Browser 2019.09.03 (64-Bit)

I have not enough time to research all options but you can check these links for your focus command without tools:
https://developer.mozilla.org/en-US/doc ... ow_Handles
https://stackoverflow.com/questions/219 ... 9#21998929
https://developer.mozilla.org/en-US/doc ... _processes
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
chivracq
Posts: 8722
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Force Firefox window to Focus on screen when...?

Post by chivracq » Sun Sep 15, 2019 9:12 pm

thecoder2012 wrote:
Sun Sep 15, 2019 6:50 pm
Legalien wrote:
Tue Aug 13, 2019 12:19 am
Multiple times per day each of the browsers will visit a specific site at some point, and this site is extremely slow if the Firefox window is not centered :(
It's easy in iMacros for Firefox with v8.9.7 and a little Javascript.

Example in pure Javascript:

Code: Select all

window.screenX=((window.screen.availWidth/2)-(window.outerWidth/2));
window.screenY=((window.screen.availHeight/2)-(window.outerHeight/2));
If it's not as URL GOTO possible then as very small addon as XPI File with protocol handler api.
Legalien wrote:
Tue Aug 13, 2019 12:19 am
Is there a way for me to force the Firefox to get centered/focused/visible on the screen whenever a certain domain is visited or a certain text appears?
It would be awesome if I could do this with iMacros, but if not, any ideas of how I can accomplish this?
Focus/visible is tricky in my first tests.

But the fastest or easiest version is with powershell under Windows.

1. Powershell command:

Code: Select all

powershell -Command (New-Object -ComObject WScript.Shell).AppActivate((Get-Process firefox).MainWindowTitle)
Same for basilisk:

Code: Select all

powershell -Command (New-Object -ComObject WScript.Shell).AppActivate((Get-Process basilisk).MainWindowTitle)
Special case multi process software (e.g. waterfox):

Code: Select all

powershell -Command Get-Process waterfox
Then use the process id:

Code: Select all

powershell -Command (New-Object -ComObject WScript.Shell).AppActivate((Get-Process -Id 14700).MainWindowTitle)
2. With iMacros and Javascript:

Code: Select all

const FileFactory = new Components.Constructor("@mozilla.org/file/local;1","nsILocalFile","initWithPath");
var str_LocalProgram = "C:\\Windows\\system32\\cmd.exe";
var obj_Program = new FileFactory(str_LocalProgram); 
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(obj_Program);
var args = ["/C",'powershell -Command (New-Object -ComObject WScript.Shell).AppActivate((Get-Process firefox).MainWindowTitle)'];
process.run(true, args, args.length);
Tested with iMacros v8.9.7, Win8.1 (64-Bit) and Basilisk Browser 2019.09.03 (64-Bit)

I have not enough time to research all options but you can check these links for your focus command without tools:
https://developer.mozilla.org/en-US/doc ... ow_Handles
https://stackoverflow.com/questions/219 ... 9#21998929
https://developer.mozilla.org/en-US/doc ... _processes

Yep...!, exactly what I had meant in that Reply of mine about 'Powershell'...! 8)
I didn't have much time at that time to dig into it, and I'm not very "fluent" in 'PS' either, so I would have "suffered" anyway, ah-ah...!, but that's exactly what I meant then... 8)
Excellent, @thecoder2012...! :D

Hum, and I had tested also in the meantime the 'Alt^Tab' / 'Shift^Alt^Tab' "Option" triggered from the 'EVENT' Mode I had also mentioned, and it doesn't work, (nothing "happens"), the 'EVENT' Mode can only trigger Shortcuts that are (also) defined at the Browser Level, while 'Alt^Tab' is apparently a pure OS (Win) Shortcut Command... :|
'Ctrl^c' + 'Ctrl^v' (Copy & Paste from the OS Clipboard) are also OS-Level Shortcuts, but they are also defined and relayed in the Browser (and 99% of any Software/Apps developed for Win), so those do work with the 'EVENT' Mode... 8)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
rstancuna
Posts: 23
Joined: Sun Jun 16, 2019 10:27 pm

Re: Force Firefox window to Focus on screen when...?

Post by rstancuna » Sun Sep 15, 2019 10:35 pm

chivracq wrote:
Sun Sep 15, 2019 9:12 pm
the 'EVENT' Mode can only trigger Shortcuts that are (also) defined at the Browser Level, while 'Alt^Tab' is apparently a pure OS (Win) Shortcut Command... :|
Depends on the keys and SELECTOR as well, for example Alt+W isn't defined in browser but it does work for me. Some pages for me would need selector "HTML>BODY" while others i may need to use a cell from a bottom table "#footer>TABLE>TBODY>TR>TD" . Tho, don't think Alt+Tab will ever work regardless.
Waterfox 56.2, iMacros V8.9.7 on Windows
chivracq
Posts: 8722
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Force Firefox window to Focus on screen when...?

Post by chivracq » Mon Sep 16, 2019 12:38 am

rstancuna wrote:
Sun Sep 15, 2019 10:35 pm
chivracq wrote:
Sun Sep 15, 2019 9:12 pm
the 'EVENT' Mode can only trigger Shortcuts that are (also) defined at the Browser Level, while 'Alt^Tab' is apparently a pure OS (Win) Shortcut Command... :|
Depends on the keys and SELECTOR as well, for example Alt+W isn't defined in browser but it does work for me. Some pages for me would need selector "HTML>BODY" while others i may need to use a cell from a bottom table "#footer>TABLE>TBODY>TR>TD" . Tho, don't think Alt+Tab will ever work regardless.

Hum, don't know what 'Alt^w' is supposed to do...?, does nothing for me (manually) in PM v26.3.3 nor FF v55.0.3 (+Win10_x64).

When I said "defined or relayed by the Browser", it could also be automatically inherited from the Core-Prog-Language the Software was written in, depending on what Type of Field..., which I think is very much probably the correct "Explanation"...

I used to program, hum..., quite a few years ago, 15 or 20 maybe now, in Client-Server 4GL-OO Languages, like 'PowerBuilder' (I was a Senior Programmer, working for 'Sybase' at that time), 'Delphi', and a few others, 'VB' of course which was then just a pale plagiated Copy of 'PB', (I was always "surprised" 'Sybase' never pressed Charges, but 'MS' very soon bought some 'Sybase' DB-Engine as the Base for their own 'MS SQL-Server', for a very good Price probably, and within a few years 'MS' "killed" both 'PB' with 'VB' and the 'Sybase' DB Products with 'SQL Server'...), and the compiled Prog would be EXE + DLL's, and as far as I can remember, I don't think I ever had to "care" about defining/declaring whatever for C&P to work for example, it simply worked "out of the box"... I had to care about Memory, and releasing it, ah-ah...!, and Menus in Windows and defining Menu Shortcuts yes, but never about C&P... :|
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply