0

I made a simple batch script with two diff options, it kinda annoys me that it covers my whole screen although there are 2 lines visible. It would be cool if someone teaches me how to edit the script so that it opens in a smaller (resized window). This is my current script:

@echo off
title Changing Configs..
:main
echo 1 = trade time
echo 2 = grind time
set /p ibo=
if %ibo% == 1 goto trade
if %ibo% == 2 goto grind

:trade
ren "config.yml" "config - nakano.yml"
ren "config - senpai.yml" "config.yml"
pause
exit

:grind
ren "config.yml" "config - senpai.yml"
ren "config - nakano.yml" "config.yml"
pause
exit

I want it to look like this if I run it without resizing it manually

Sneazy好
  • 1
  • 1
  • the `mode` command is made for this purpose: `mode /?` – Stephan Apr 16 '22 at 20:09
  • If you are running the script from a shortcut, you can configure the window size within the shortcut properties. Otherwise open a Command Prompt window, type `mode /?`, and press the `[ENTER]` key, to find out how to do it within the script itself. – Compo Apr 16 '22 at 20:13
  • I recommend to read also my answer on [How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?](https://stackoverflow.com/a/49834019/3074564) Do not use `set /P` for a choice menu. There is the command __CHOICE__ for this purpose. It is also better to use `exit /B` instead of just `exit`. – Mofi Apr 16 '22 at 20:59
  • @Stephan - unless they're using Terminal, which doesn't react to `mode con` at all for some reason (although there's an issue on Microsoft's github about it, so theoretically it will someday) – SomethingDark Apr 16 '22 at 23:29

2 Answers2

0

Not sure if there is a way to change the window's size, run mode, or whatever it is called from the batch script itself. It really doesn't matter since you can either control it via shortcut, or just avoid the situation all together.

If you look at the comments on your question, Compo mentioned using a shortcut - this is the most direct answer to your question. Do the following to create desired shortcut:

  1. Create a shortcut by opening windows explorer and navigating to where your batch file is.
  2. Start a drag-n-drop operation by grabbing the batch file with the mouse and moving the mouse off of the file, but DO NOT let go yet. Hold down the CTRL+Shift and the icon you are dragging, or the text under it, will change to indicate you are about to create a link (A.K.A. shortcut). Letting go in the same folder will work, but you may want to move the shortcut later. Alternatively, you could try bringing up a context menu on the batch file by moving the mouse over it and using the secondary click, and then select "create shortcut", which should be found fairly far done on the context menu.
  3. Select the newly created shortcut with the mouse and on the keyboard type Alt+Enter - a properties window should appear. If for some reason that fails. you can use the mouse to bring up a context menu on the newly created shortcut (same way as described in step 2) and select "Properties" (Should be at bottom of context menu).
  4. Go to the "Shortcut" tab in the "Properties" windows, select "Normal windows" from "Run:" section, and click the "OK" button (See image below). enter image description here

The resulting icon can be moved to the desktop or pinned to the taskbar by dragging to the taskbar.

Or instead, you could rewrite your code so it doesn't ask any questions and just does the job. If you only have 2 choices, why not check which is current, change to the other, and report which one is now the current option?

The following code:

  1. Verifies that copies of both the senpai and nakano configs exist before making any changes.
  2. Checks if the file "Nakano.Active" exist, if so then it does the code to switch to senpai, else it assumes senpai is active and does the code to switch to nakano.
  3. Replaces the current "config.yml" file with the desired configuration.
  4. Deletes the current "{Mode}.Active" file, "Nakano.Active" or "Senpai.Active", as needed.
  5. Creates a new Active file, or flag, to indicate the current mode. That is , creates "Senpai.Active" or "Nakano.Active", as needed.
  6. Echos/reports out what mode it just switch to.
  7. Waits for 2.25 seconds, giving you the time to see what mode it switched to. Change the 225 to the number of centiseconds you want the code to wait before continuing.
  8. Executes EXIT which closes the window.
@ECHO OFF
    IF NOT EXIST "config - senpai.yml" GOTO :DoExit
    IF NOT EXIST "config - nakano.yml" GOTO :DoExit
    IF EXIST Nakano.Active (
        COPY /Y "config - senpai.yml" "config.yml" >NUL
        DEL Nakano.Active 2>NUL
        ECHO;Senpai >Senpai.Active
        ECHO;Senpai Mode
    ) ELSE (
        COPY /Y "config - nakano.yml" "config.yml" >NUL
        DEL Senpai.Active 2>NUL
        ECHO;Nakano >Nakano.Active
        ECHO;Nakano Mode
    )
    REM Pause for 2.25 seconds
    SET Centiseconds=225
    SET "NOWTIME=%TIME:00.=%"
    SET "NOWTIME=%NOWTIME:.=%"
    FOR /F "TOKENS=1-3 DELIMS=:" %%G IN ("%NOWTIME::0=:%") DO SET /A "StartCentiseconds=(%%G*60+%%H)*6000+%%I"
    SET /A EndCentiseconds=StartCentiseconds+Centiseconds
:GetNow
    SET "NOWTIME=%TIME:00.=%"
    SET "NOWTIME=%NOWTIME:.=%"
    FOR /F "TOKENS=1-3 DELIMS=:" %%G IN ("%NOWTIME::0=:%") DO SET /A "NowCentiseconds=(%%G*60+%%H)*6000+%%I"
    IF %NowCentiseconds% LSS %StartCentiseconds% SET /A NowCentiseconds=NowCentiseconds+8640000
    IF %NowCentiseconds% LSS %EndCentiseconds% GOTO :GetNow
:DoExit
EXIT
Darin
  • 1,423
  • 1
  • 10
  • 12
  • Tysm for that explanation, I am kinda new to stackoverflow and don't know how to respond to comments. Anyways ty and Stephan and Compo for telling me abt the Mode command and ty mofi for your recommendation. It's also really nice that you summarized everything and wrote a script extra for my question Darin. It's really cool that everyone here is always ready to help others <3 – Sneazy好 Apr 18 '22 at 22:25
  • @Sneazy好, you are welcome! In my own case, I've probably googled several hundred times where Stack Overflow answered my question. I'm now at a technical level that I can at times actually help others. And also, this is better for me in multiple ways than spending 4 hours in an evening playing a video game. I think writing code to solve a problem is to me what Sudoku is to other people. And then there has been a few times where it seems that I really helped someone, which is a nice experience to have. – Darin Apr 19 '22 at 11:38
0

As per comments simply add mode 40,10 or similar at start of file

enter image description here

@echo off & mode 40,10
title Changing Configs..
......
K J
  • 8,045
  • 3
  • 14
  • 36