Finding each win position & applying a command to each one

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Finding each win position & applying a command to each one

22 Dec 2019, 16:19

the following script is working

It gets the window position of the Word window active, and applies the benefit of the Toggle Full Word command to that specific Word window (in result the window position of that specif Word file remains without the main Tool bar and without the Quick Access Toolbar)

but when I have two or more Word docs opened the script is not working well for the other Word files (just maximized them without bringing them back to the previous win position).

So, how can I add the option of finding the Win Position for each Word opened and applying to each one the benefit of Toggle Full Word?

Code: Select all

+!sc027::  ;ToggleFull into same window position
      WinGet, active_id, ID, A
      WinGetPos, X,Y,W,H,ahk_id %active_id%
      Send ^!{F5} ;ToggleFull
      Sleep 500
      WinRestore, ahk_id %active_id%
      WinMove ahk_id %active_id%,,%X%`,%Y%`,%W%`,%H%
      WinActivate
    Return
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

23 Dec 2019, 06:18

You have to loop through all windows of Word (OpusApp).
This script doesn't toggle the windows in full screen on my computer because ctrl+altF5 has no function. I think that is a user shortcut on your system. So it is untested.

Code: Select all

WinGet, Window, List, ahk_class OpusApp
Loop, %Window% 
{ 

	WinGetPos, X,Y,W,H, % "ahk_id " Window%A_Index%
	WinActivate, % "ahk_id " Window%A_Index%
	Send ^!{F5} ;ToggleFull
	Sleep 500
	WinRestore, % "ahk_id " Window%A_Index%
	WinMove % "ahk_id " Window%A_Index%,,%X%`,%Y%`,%W%`,%H%
	WinActivate
	
}
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Re: Finding each win position & applying a command to each one

23 Dec 2019, 12:03

thank for your Christmas gift:) !

(indeed I customized the command ToggleFull for the script since Word does not assign any key shortcut for that command)

The script works though it has this error message for the WinMove line that says:

The following variable name contains an illegal character:
"-1"


why?
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

23 Dec 2019, 16:26

At a few tests with three windows I had a fourth and empty entry in the list. It could be fixed with an check if the ID exists.
I'll check it tomorrow. To much Glühwein to debug. :lol:
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

26 Dec 2019, 08:20

Sure. When you want to test something it didn't happen anymore. =)
Try this one.

Code: Select all

WinGet, Window, List, ahk_class OpusApp
Loop, %Window% 
{ 
	if Window%A_Index%
	{
		WinGetPos, X,Y,W,H, % "ahk_id " Window%A_Index%
		WinActivate, % "ahk_id " Window%A_Index%
		Send ^!{F5} ;ToggleFull
		Sleep 500
		WinRestore, % "ahk_id " Window%A_Index%
		WinMove % "ahk_id " Window%A_Index%,,%X%`,%Y%`,%W%`,%H%
		WinActivate
	}
} 
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Re: Finding each win position & applying a command to each one

26 Dec 2019, 13:39

it works when I have only one Word docx

but when I have two Word docs or more it does not work (goes back to show toolbar and Quick Access Toolbar, and also brings back that error message mentioned)

have you tested it?

(I wonder if there would be any way to just tell Word to avoid displaying the main toolbar and the Quick Access Toolbar. That's the purpose of the whole script)
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

27 Dec 2019, 07:20

I've tested it. But I didn't have minimized Word windows. The new script checks it.

Code: Select all

WinGet, Window, List, ahk_class OpusApp
Loop, %Window% 
{ 
	if Window%A_Index%
	{
		WinGetPos, X,Y,W,H, % "ahk_id " Window%A_Index%
		WinActivate, % "ahk_id " Window%A_Index%
		Send ^!{F5} ;ToggleFull
		Sleep 500
		MsgBox %X%`,%Y%`,%W%`,%H%
		if (X >= 0)
		{
			WinMove % "ahk_id " Window%A_Index%,, %X% ,%Y% ,%W% ,%H%
		} else {
			WinMinimize % "ahk_id " Window%A_Index%
		}
		WinActivate
	}
} 
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Re: Finding each win position & applying a command to each one

27 Dec 2019, 10:57

now, it's worse.
It is not working even with only one Word open nor with more than one
it appears also a MsgBox
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

27 Dec 2019, 11:12

Oh. Forgot to clean it up.
delete the line with Msgbox.
But that is very strange. It's working perfectly on my PC.
Do you have additional lines in your script? Could you paste it completely?
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

27 Dec 2019, 14:43

Just checked the code on a second PC. Running out of AHK Studio and as standalone script. It works. Sorry, that I can't help.

Code: Select all

WinGet, Window, List, ahk_class OpusApp
Loop, %Window% 
{ 
	if Window%A_Index%
	{
		WinGetPos, X,Y,W,H, % "ahk_id " Window%A_Index%
		WinActivate, % "ahk_id " Window%A_Index%
		Send ^!{F5} ;ToggleFull
		Sleep 500
		if (X >= 0)
		{
			WinMove % "ahk_id " Window%A_Index%,, %X% ,%Y% ,%W% ,%H%
		} else {
			WinMinimize % "ahk_id " Window%A_Index%
		}
		WinActivate
	}
} 
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Re: Finding each win position & applying a command to each one

27 Dec 2019, 14:56

it does not work (:
even for only one Word opened
I can see that it minimizes but finally it maximizes again (: !!
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

27 Dec 2019, 15:50

OK. But that is all what your original script does. It goes in Full screen, sleeps 500 and then restore the old position and dimensions.
I think, I didn't get your problem exactly. Sorry.
You want to get all three Word windows in Full Screen? But when you set one Word in Full screen, then automatically all documents are full screen, too.
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Re: Finding each win position & applying a command to each one

27 Dec 2019, 15:57

my goal is to keep the same windows size that all my current Word docs have but without any bar (main toolbar or Quick Access tool bar).

The logic should be:
1. discover and get the size of each win of any Word opened
2. apply ToggleFull (that will maximize all the windows)
3. apply to each window the size it got before it was applied toggleFull

is it possible to create a script for that?
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

27 Dec 2019, 16:09

OK. Full screen is full screen. You want this view (like a distraction free view) in every "small" window. I don't think that it will work. But I'm not a Word specialist, problably someone can help you.
The only tip I can give is to minimize the ribbon bar. Just click on the little arrow on the right side.
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Re: Finding each win position & applying a command to each one

27 Dec 2019, 16:44

"ToggleFull" not only hides the ribbon, hides the main toolbar and Quick Access Tool bar and maximizes the Word file. However if after that you apply a specific Window Size you can have the advantages of not viewing any bar while working not in the maximize mode.

So, my desire is a script that remembers the current window and then applies it after ToggleFull
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

27 Dec 2019, 17:00

You could use my script and divide it in two hotkey. One hotkey to store all the windows and their parameters in an array and activate the full screen. Another hotkey reads the array and restores the windows.
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Re: Finding each win position & applying a command to each one

27 Dec 2019, 17:29

mmm
my knowledge is quite limited
if that's possible for you great, if not .... (patience)
thanks so much for your help
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Finding each win position & applying a command to each one

30 Dec 2019, 11:05

This was a very strange problem. I created the script as told above with the two hotkeys. As I tested it, I created the full screen shortcut on my PC.
And after the first test, I saw what you mean. Didn't know, that toggling into full screen mode and minimizing the windows, the small windows remain in this full screen view.
Sorry for that misunderstanding. I learned a lot. This script works on my PC.

Code: Select all

F6::
WinGet, Window, List, ahk_class OpusApp
Loop, %Window% 
{ 
	if Window%A_Index%
	{
		WinGetPos, X,Y,W,H, % "ahk_id " Window%A_Index%
		WinActivate, % "ahk_id " Window%A_Index%
		Send ^!{F5} ;ToggleFull
		sleep, 1000
		WinMove % "ahk_id " Window%A_Index%,, %X% ,%Y% ,%W% ,%H%
	}
}
AmDeG 11
Posts: 388
Joined: 28 Nov 2013, 11:42

Re: Finding each win position & applying a command to each one

30 Dec 2019, 14:16

Glad to know that finally you got my idea :) Sorry if I wasn't able to explain myself

I tested with just one Word and it is not working: the result is a maximized window (without any bars)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, changlish76, cleancode, Google [Bot], norot41087, ntepa, Xeo786 and 117 guests