Enable "autohide taskbar" when app is in focus, disable when not Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Enable "autohide taskbar" when app is in focus, disable when not

Post by astute65_aardvark20 » 10 Jan 2024, 10:03

Hi, I have made a script that minimizes any other Adobe app except the one that is in focus:

Code: Select all

#Persistent
Run, "C:\Users\user\OneDrive\Apps & Utilities\MonitorProfileSwitcher\MonitorSwitcher.exe" -load:"C:\Users\user\AppData\Roaming\MonitorSwitcher\Profiles\Dual Monitor.xml"
SetTimer Subroutine0, 2000
SetTimer Subroutine1, 2000
SetTimer Subroutine2, 2000
SetTimer Subroutine3, 2000
SetTimer Subroutine4, 2000
SetTimer Subroutine5, 2000
return

Subroutine0() {
If WinActive("ahk_class Photoshop")
    {
        WinMinimize, ahk_class illustrator
        WinMinimize, ahk_class audition24
        WinMinimize, ahk_class Premiere Pro
        WinMinimize, ahk_class indesign
        WinMinimize, ahk_class incopy
    }
}

Subroutine1()
{
    If WinActive("ahk_class illustrator")
    {
        WinMinimize, ahk_class Photoshop
        WinMinimize, ahk_class audition24
        WinMinimize, ahk_class Premiere Pro
        WinMinimize, ahk_class indesign
        WinMinimize, ahk_class incopy
    }
}

Subroutine2()
{
    If WinActive("ahk_class audition24")
    {
        WinMinimize, ahk_class Photoshop
        WinMinimize, ahk_class illustrator
        WinMinimize, ahk_class Premiere Pro
        WinMinimize, ahk_class indesign
        WinMinimize, ahk_class incopy
    }
}

Subroutine3()
{
    If WinActive("ahk_class Premiere Pro")
    {
        WinMinimize, ahk_class Photoshop
        WinMinimize, ahk_class illustrator
        WinMinimize, ahk_class audition24
        WinMinimize, ahk_class indesign
        WinMinimize, ahk_class incopy
    }
}

Subroutine4()
{
    If WinActive("ahk_class indesign")
    {
        WinMinimize, ahk_class Photoshop
        WinMinimize, ahk_class illustrator
        WinMinimize, ahk_class audition24
        WinMinimize, ahk_class Premiere Pro
        WinMinimize, ahk_class incopy
    }
}

Subroutine5()
{
    If WinActive("ahk_class incopy")
    {
        WinMinimize, ahk_class Photoshop
        WinMinimize, ahk_class illustrator
        WinMinimize, ahk_class audition24
        WinMinimize, ahk_class Premiere Pro
        WinMinimize, ahk_class indesign
    }
}
I also found this nifty script that can toggle the Windows taskbar autohide (it only toggles from one state to another):

Code: Select all

VarSetCapacity(APPBARDATA, A_PtrSize=4 ? 36:48)

NumPut(DllCall("Shell32\SHAppBarMessage", "UInt", 4 ; ABM_GETSTATE
                                        , "Ptr", &APPBARDATA
                                        , "Int")
? 2:1, APPBARDATA, A_PtrSize=4 ? 32:40) ; 2 - ABS_ALWAYSONTOP, 1 - ABS_AUTOHIDE
, DllCall("Shell32\SHAppBarMessage", "UInt", 10 ; ABM_SETSTATE
                                , "Ptr", &APPBARDATA)
KeyWait, % A_ThisHotkey
ExitApp
What I would like is to add an else statement and function to each subroutine in my script so that when any Adobe app is in focus, the taskbar will autohide, and when no Adobe app is in focus, the taskbar will not autohide. The problem is that the taskbar script is way beyond me and I don't know how to convert it to do what I want. Anybody familiar with this bit of wizardry?
Last edited by astute65_aardvark20 on 23 Jan 2024, 12:50, edited 2 times in total.

User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Enable "autohide taskbar" when app is in focus, disable when not  Topic is solved

Post by mikeyww » 10 Jan 2024, 12:52

Ideas are below.

Code: Select all

#Requires AutoHotkey v1.1.35
#Persistent
Process Priority,, B
SetTimer Check, 1000
Check:
WinActive("A")
WinGet procPath, ProcessPath
WinGetClass winClass
If !InStr(procPath, "explorer.exe") || winClass = "CabinetWClass" {
 ToolTip % procPath
 adobe    := InStr(procPath, "\Adobe\") > 0
 autoHide := DllCall("Shell32\SHAppBarMessage", "UInt", 4 ; ABM_GETSTATE
           , "Ptr", &APPBARDATA, "Int")
 If (adobe ^ autoHide)
  taskbarAutoHide(adobe)
}
Return

taskbarAutoHide(autoHide:= True) {
 RunWait % "powershell -command ""&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3'"
         . ";$v=(Get-ItemProperty -Path $p).Settings;$v[8]="
         . (autoHide ? 3 : 2)
         . ";&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"""
        ,, "Hide"
 SoundBeep 800
 Sleep 10000
}

astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by astute65_aardvark20 » 20 Jan 2024, 14:13

Hi mikeyww, sorry for the late response!

Your script did not work at first, though I was hearing a beeping whenever I alt-tabbed in or out of an Adobe app. Then I remembered that I have ExplorerPatcher installed and that it is replacing or overriding something to do with the Win10/11 taskbar.

So if I uninstall ExplorerPatcher, your script works perfectly! Sadly I must have it installed, so I am just now researching registry entries for ExplorerPatcher, hopefully I can figure out an alternative Powershell script...

User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by mikeyww » 20 Jan 2024, 14:50

I found that taskbar is tricky. With your original script, I found that it sometimes works but sometimes does not. The PowerShell script works but requires terminating Explorer, so it is clunky. Others here may have better ideas.

astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by astute65_aardvark20 » 20 Jan 2024, 17:28

I did manage to find the discussion thread on EP's GitHub page for its autohide feature. Lo and behold, it's a similar AHK script!

The way valinet did it, double-clicking on the taskbar will toggle the autohide on and off:

Code: Select all

VarSetCapacity(APPBARDATA, A_PtrSize=4 ? 36:48)
~LButton::
   If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)
   {
      WinGetClass, Class, A
      If ( Class = "Shell_TrayWnd" )

	NumPut(DllCall("Shell32\SHAppBarMessage", "UInt", 4 ; ABM_GETSTATE
											, "Ptr", &APPBARDATA
											, "Int")
	? 2:1, APPBARDATA, A_PtrSize=4 ? 32:40) ; 2 - ABS_ALWAYSONTOP, 1 - ABS_AUTOHIDE
	, DllCall("Shell32\SHAppBarMessage", "UInt", 10 ; ABM_SETSTATE
									   , "Ptr", &APPBARDATA)
   }
return
Something about that is interfering with your script...


astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by astute65_aardvark20 » 20 Jan 2024, 17:51

mikeyww wrote:
20 Jan 2024, 17:43
It worked here.
You are using ExplorerPatcher too?

Edit: I am getting the beep and Explorer.exe is restarting, but it just keeps repeatedly doing that every time the loop refreshes if Photoshop/etc is in focus.

If I run the powershell script in a Terminal shell I get:

Code: Select all

At line:1 char:111
+ ... n\Explorer\StuckRects3';=(Get-ItemProperty -Path ).Settings;[8]=3;&Se ...
+                                                                  ~
Missing type name after '['.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingTypename

astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by astute65_aardvark20 » 20 Jan 2024, 18:19

In addition, looking into the registry entry

Code: Select all

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3
I don't seem to have the correct binary values under the Settings value name, as shown in this tutorial:
ImageImage

Instead of "7A" or "7B", there is an "03" after the "00000008":
Image

Following the instructions there after replicating the binary values exactly also produces no effect on my system...
Last edited by astute65_aardvark20 on 20 Jan 2024, 18:30, edited 1 time in total.

astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by astute65_aardvark20 » 20 Jan 2024, 18:25

I've also tried running a modified version of the PowerShell script (found on Microsoft Answers):

Code: Select all

$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3'
$v=(Get-ItemProperty -Path $p).Settings
$v[8]=3
Set-ItemProperty -Path $p -Name Settings -Value $v
Stop-Process -f -ProcessName explorer
And this does nothing, and reverts the registry entry for StuckRects3 back to:
Image
Last edited by astute65_aardvark20 on 20 Jan 2024, 23:44, edited 1 time in total.

User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by mikeyww » 20 Jan 2024, 18:56

Sorry, no, I am not using ExplorerPatcher.

astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by astute65_aardvark20 » 21 Jan 2024, 10:38

Oh my worrrd! I finally got this to work, phew!

So, ExplorerPatcher allows Win11 users to revert the taskbar to the Win10 style. In that case, the ABS_AUTOHIDE bit that will actually trigger the taskbar auto-hide for Win10 will be inside of the "Settings" REG_BINARY in the "Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRectsLegacy" key. Anyone using the Win11 taskbar would use "Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3" instead.

So, for me, the AHK script will look like this (the change is on line 20):

Code: Select all

#Requires AutoHotkey v1.1.35
#Persistent
Process Priority,, B
SetTimer Check, 1000
Check:
WinActive("A")
WinGet procPath, ProcessPath
WinGetClass winClass
If !InStr(procPath, "explorer.exe") || winClass = "CabinetWClass" {
 ToolTip % procPath
 adobe    := InStr(procPath, "\Adobe\") > 0
 autoHide := DllCall("Shell32\SHAppBarMessage", "UInt", 4 ; ABM_GETSTATE
           , "Ptr", &APPBARDATA, "Int")
 If (adobe ^ autoHide)
  taskbarAutoHide(adobe)
}
Return

taskbarAutoHide(autoHide:= True) {
 RunWait % "powershell -command ""&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRectsLegacy'"
         . ";$v=(Get-ItemProperty -Path $p).Settings;$v[8]="
         . (autoHide ? 3 : 2)
         . ";&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"""
        ,, "Hide"
 SoundBeep 800
 Sleep 10000
}
The reason it took me so long to figure this out is because the first time I changed the script I made a typo on the section with the PowerShell script, which threw me off and forced me down a dozen useless rabbit holes.

Also, I know how to run PowerShell scripts in AHK now, so that's great.

astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Re: Enable "autohide taskbar" when app is in focus, disable when not

Post by astute65_aardvark20 » 22 Jan 2024, 23:51

So, in case anyone else stumbles upon this thread, I discovered a program called 7+ Taskbar Tweaker that allows users to assign a hotkey to trigger the taskbar auto-hide (Value Data 6). Using the Advanced Options Keyboard Shortcuts, I assigned F24 (Virtual Keycode 0x87) to this function:
Image
The interesting thing about Taskbar Tweaker is that it can toggle the auto-hide without restarting Explorer.exe!

So I changed the script provided by mikeyww and replaced the PowerShell script with Send F24:

Code: Select all

#Persistent

Run, "C:\Users\user\OneDrive\Apps & Utilities\MonitorProfileSwitcher\MonitorSwitcher.exe" -load:"C:\Users\user\AppData\Roaming\MonitorSwitcher\Profiles\Dual Monitor.xml"

SetTimer Subroutine0, 5000
SetTimer Subroutine1, 5000
SetTimer Subroutine2, 5000
SetTimer Subroutine3, 5000
SetTimer Subroutine4, 5000
SetTimer Subroutine5, 5000

Process Priority,, B
SetTimer Check, 1000
Check:
WinActive("A")
WinGet procPath, ProcessPath
WinGetClass winClass
If !InStr(procPath, "explorer.exe") || winClass = "CabinetWClass" {
    adobe       := InStr(procPath, "\Adobe\") > 0
    autoHide    := DllCall("Shell32\SHAppBarMessage", "UInt", 4 ; ABM_GETSTATE
                , "Ptr", &APPBARDATA, "Int")
    If (adobe ^ autoHide)
        taskbarAutoHide(adobe)
}
Return

taskbarAutoHide(autoHide:= True) {
    Send, {F24}
    Sleep 5000
}
return

Subroutine0:
If WinActive("ahk_class Photoshop") {
    WinMinimize, ahk_class illustrator
    WinMinimize, ahk_class audition24
    WinMinimize, ahk_class Premiere Pro
    WinMinimize, ahk_class indesign
    WinMinimize, ahk_class incopy
}
Return

Subroutine1:
If WinActive("ahk_class illustrator") {
    WinMinimize, ahk_class Photoshop
    WinMinimize, ahk_class audition24
    WinMinimize, ahk_class Premiere Pro
    WinMinimize, ahk_class indesign
    WinMinimize, ahk_class incopy
}
Return

Subroutine2:
If WinActive("ahk_class audition24") {
    WinMinimize, ahk_class Photoshop
    WinMinimize, ahk_class illustrator
    WinMinimize, ahk_class Premiere Pro
    WinMinimize, ahk_class indesign
    WinMinimize, ahk_class incopy
}
Return

Subroutine3:
If WinActive("ahk_class Premiere Pro") {
    WinMinimize, ahk_class Photoshop
    WinMinimize, ahk_class illustrator
    WinMinimize, ahk_class audition24
    WinMinimize, ahk_class indesign
    WinMinimize, ahk_class incopy
}
Return

Subroutine4:
If WinActive("ahk_class indesign") {
    WinMinimize, ahk_class Photoshop
    WinMinimize, ahk_class illustrator
    WinMinimize, ahk_class audition24
    WinMinimize, ahk_class Premiere Pro
    WinMinimize, ahk_class incopy
}
Return

Subroutine5:
If WinActive("ahk_class incopy") {
    WinMinimize, ahk_class Photoshop
    WinMinimize, ahk_class illustrator
    WinMinimize, ahk_class audition24
    WinMinimize, ahk_class Premiere Pro
    WinMinimize, ahk_class indesign
}
Return
So far so good!

Post Reply

Return to “Ask for Help (v1)”