Automate adjusting Windows console font and layout Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Automate adjusting Windows console font and layout

18 Feb 2024, 11:02

I've been hunting for a way to adjust the settings in a PowerShell or Cmd Prompt console using PowerShell code for months (maybe years), and so far, it seems completely impossible to adjust those settings, so I'd appreciate some help on this as Autohotkey is the ultimate Swiss army knife of course. I would like to do the following:

- Open up Windows PowerShell or Cmd console.
- Alt+Space to open the menu, then "P" to open Properties.
- Shift+Tab to move between tabs, then right-cursor once to get to the Font tab.
- Tab once to get to Font field and then enter "18" my preferred font size.
- Shift+Tab to get back to the tabs, then right-cursor once to get to the Layout tab.
- Tab once to get to the Buffer Height field, and enter "9999".
- Tab twice to get to the Windows Size Width and set it to 140.
- Tab once to get to Window Size Height field and set it to 32.

In addition, while these operations are going on, I would the focus to lock onto the Properties dialogue, so that a stray mouse click or keyboard press won't mess this up and send the keypresses into other windows that are brought into focus.

I can send keypresses, but I often find it a bit hit and miss as focus does change, or, maybe a dialogue does not open in time, so I have to then put sleep's in to hopefully wait long enough for a diaogue to open properly (which seems wrong, surely AutoHotkey can stick to the dialogue and ensure that these keypresses are only going to the correct fields etc?). Help on that would help me with a lot of scripts actually, as guaranteed control when navigating dialogues is something that I can't do very well. 👍
RussF
Posts: 1301
Joined: 05 Aug 2021, 06:36

Re: Automate adjusting Windows console font and layout

19 Feb 2024, 08:30

Like you, I prefer a certain background/foreground color, font and font size, etc. I get that automatically whenever I open a Command/Powershell prompt. It sounds like you have to set those every time you open one. For years, I have let Windows take care of it - no need for AHK. All you need is a shortcut to either of them.
image.png
image.png (3.83 KiB) Viewed 271 times
The properties of the shortcut contain all the properties you want to set, and will remain set permanently.
image.png
image.png (30.74 KiB) Viewed 271 times
You can leave the shortcut on your desktop, pin it to your task bar or hide it away somewhere else. You can set a Windows shortcut key right there in the properties, or use an AHK hotkey to run the shortcut.

Russ
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: Automate adjusting Windows console font and layout

19 Feb 2024, 21:34

I agree with RussF above. You don't need an AHK script for what you're looking for. The features are already built into Windows. You said earlier:
roysubs wrote:
18 Feb 2024, 11:02
I've been hunting for a way to adjust the settings in a PowerShell or Cmd Prompt console using PowerShell code for months (maybe years), and so far, it seems completely impossible to adjust those settings,

There are 2 ways to adjust the font/color/layout of the command shell in Windows. Make sure you are changing it through 'Defaults' menu option as shown here:

command window default.png
command window default.png (59.78 KiB) Viewed 252 times
roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Re: Automate adjusting Windows console font and layout

22 Feb 2024, 12:25

Thanks. I know what you mean, and I do adjust things this way etc; it's just that I want this as a part of standard customisations that I apply to a system (I apply all of these customisations to my dozens of systems and VMs).

The "Defaults" point is a good one, as I normally just go into Properties and forgot that this is a bit better. Maybe what I can do is try and use a registry capture program like RegShot then see exactly what registry keys are changed, then reapply these to new systems.

I was hoping to get a proper way to manipulate windows in AutoHotkey though. Everything I do is a mess with UI as if I automate keypresses and focus changes the keypresses go all over the place, so was hoping to learn how to lock the focus with AutoHotkey.
garry
Posts: 3788
Joined: 22 Dec 2013, 12:50

Re: Automate adjusting Windows console font and layout  Topic is solved

22 Feb 2024, 13:11

I set once in cmd the font and size
script below set x y w h > color gray/black T:70 or e.g. T:0E is black yellow, WIN-TITLE, lines=>height cols=>width > depending fontsize settings in DOS
e.g. set lines=2000 allow to vertical scroll in DOS window

Code: Select all

#Requires AutoHotkey v1.1.33
#warn
#singleinstance,force
#NoEnv                       ;- Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input               ;- Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;- Ensures a consistent starting directory.
e4x=
(Ltrim join&&
@echo off
echo date=
date /t
echo time=
time /t
ver
dir
)
Run, %COMSPEC% /T:0E /U /k "title  AHK_CMD_TEST && mode con lines=1920 cols=120&&%e4x%",
  ;- color gray/black T:70  e.g. T:0E is black yellow, WIN-TITLE, lines=>height  cols=>width > depending fontsize settings in DOS
Winwait,ahk_class ConsoleWindowClass
WinMove,ahk_class ConsoleWindowClass,, 0,0,,
return
DOScommandhere F9 / dir from active folder / see chinese characters from filename in %F1%

Code: Select all

;- DOScommandhere F9 / dir from active folder / 
;- DOS winmove to position x y w h   lines=>height  cols=>width is depending from fontsize settings in DOS
;- see DOS window and a file ( see also chinese characters from DIR command )
;-
#Requires AutoHotkey v1.1.33
#warn
#singleinstance,force
#NoEnv                       ;- Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input               ;- Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;- Ensures a consistent starting directory.
Fileencoding, CP1200
aa:="",dirx:=""
F1:=a_desktop . "\DOSoutput11.txt"
;- 
$F9::
gosub,a1
;-
e4x=
(Ltrim join&&
@echo off
echo date=
date /t
echo time=
time /t
ver
dir
)
Run, %COMSPEC% /T:0e /U /k "title  %dirx% && mode con lines=1920 cols=80&&%e4x%",%dirx%  ;- color gray/black T:70  e.g. T:0E is black yellow, WIN-TITLE, lines=>height  cols=>width, depending fontsize settings in DOS
Winwait,ahk_class ConsoleWindowClass
WinMove,ahk_class ConsoleWindowClass,, 0,0,,
;sleep,800  ;- for test > if ready send later 2 commands :
;controlsend,ahk_parent,{text}ver`n,ahk_class ConsoleWindowClass
;controlsend,ahk_parent,{text}dir`n,ahk_class ConsoleWindowClass
;-
sleep,300
Runwait, %Comspec% /U /C (cd %dirx%&&dir) 2>&1 >"%f1%",, Hide   ;- file is UTF-16 LE see also chinese characters
;-
;FileRead,text1, *P1200 %f1%
FileRead,text1,%f1%
msgbox,%text1%
return
;-------------------
a1:
;- tmplinshi / DOScommandhere WIN11 https://www.autohotkey.com/boards/viewtopic.php?p=33858#p33858
If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass") 
dirx:=""
        WinHWND := WinActive()
        For win in ComObjCreate("Shell.Application").Windows
            If (win.HWND = WinHWND) 
			{
                dirx := SubStr(win.LocationURL, 9) ; remove "file:///"
                dirx := RegExReplace(dirx, "%20", " ")
                Break
            }
if dirx=
   dirx:=a_desktop
return
;==================================================================================
esc::exitapp
roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Re: Automate adjusting Windows console font and layout

24 Feb 2024, 05:08

These are great @garry, thanks very much. Playing with these now. 👌
garry
Posts: 3788
Joined: 22 Dec 2013, 12:50

Re: Automate adjusting Windows console font and layout

25 Feb 2024, 15:36

I have a new windows version from WIN-11 , now this worked ( example x-pos at 50% , w=50% height=90% )
ahk_class CASCADIA_HOSTING_WINDOW_CLASS

Code: Select all

-----------------------------
Full-version      = 10.0.22631.3155 ;-- Major.Minor.BuildNumber.UBR < UBR=Update-Build-Revision ( see also cmd =ver )
Build-Name/Number = 23H2/22631
OSinstallDate     = 22. Feb. 2024 - 17:40   |   (3 days)
----

Code: Select all

;- Automate adjusting Windows console font and layout 
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=126229

#Requires AutoHotkey v1.1
#warn
#singleinstance,force
#NoEnv                       ;- Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input               ;- Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;- Ensures a consistent starting directory.
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
x:=(wa*50)/xx,y:=(ha*.2)/xx,w:=(wa*50)/xx,h:=(ha*90)/xx
e4x=
(Ltrim join&&
@echo off
echo date=
date /t
echo time=
time /t
ver
dir
)
;Run, %COMSPEC% /T:0A /U /k "title  AHK_CMD_TEST && mode con lines=1920 cols=60&&%e4x%",,,
Run, %COMSPEC% /T:0A /U /k "title  AHK_CMD_TEST &&%e4x%",,,

  ;- color gray/black T:70  e.g. T:0E is black yellow, WIN-TITLE, lines=>height  cols=>width > depending fontsize settings in DOS
Winwait,ahk_class CASCADIA_HOSTING_WINDOW_CLASS 
WinMove,ahk_class CASCADIA_HOSTING_WINDOW_CLASS,,%x%,%y%,%w%,%h% 
sendinput,ver
;- OR older version :
;Winwait,ahk_class ConsoleWindowClass
;WinMove,ahk_class ConsoleWindowClass,,0,0,,
return
esc::exitapp
;=====================================================	
/*
cmd /? >  color /? 
  Background:     Foreground:
  -----------------------------------
  0 = Black       8 = Gray
  1 = Blue        9 = Light Blue
  2 = Green       A = Light Green
  3 = Turquoise   B = Light Turquoise
  4 = Red         C = Light Red
  5 = Purple      D = Light Purple
  6 = Yellow      E = Light Yellow
  7 = Light Gray  F = White
*/
;=====================================================	
EDIT found , the new DOS is Windows Power Shell as 'windows terminal' , I set to 'Windows Console host ' to see the old DOS

Code: Select all

/*
C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.19.10573.0_x64__8wekyb3d8bbwe\wt.exe
Windows Power Shell , Settings in wt.exe
-------------------------------------------
Standard Profile : ( if run wt.exe )
- as Windows Power Shell
- as DOS
- as Azure Cloud Shell
-------------------------------------------
standard terminal application : if run %comspec% / or cmd
-Windows decides
-Windows console host  >> DOS old   I used this            
-Windows Terminal      >> DOS new , like wt.exe
*/
;----------------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------
WT:="C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.19.10573.0_x64__8wekyb3d8bbwe\wt.exe"
;run,%wt%
run,%comspec% /k   
;run,cmd /k
return
;----------------------------------------------------------------------------------------------------
20240307121520_screenshot.jpg
20240307121520_screenshot.jpg (285.13 KiB) Viewed 105 times

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Kellyzkorner_NJ and 122 guests