This is a simple Windows batch script that toggles the primary display using NirCMD. It maintains a record of the last active display and switches between two predefined monitors.
- NirCMD must be downloaded and placed in a directory accessible via the system
PATH
, or stored in the same folder as this script.
By default, you can place nircmd.exe
in one of the following locations:
C:\Windows\System32\
C:\Windows\
- A custom folder added to the system
PATH
If NirCMD is not found when running the script, ensure that it is correctly placed in one of these directories or explicitly specify its full path in the batch script.
- Ensure NirCMD is installed and accessible.
- Run
switch_display.bat
to toggle between displays. - The script stores the last active display in
active.txt
and switches accordingly.
- If
active.txt
exists, the script reads the last used display. - Based on the stored value, it switches to the alternate display.
- If
active.txt
does not exist, it defaults to display1
.
If you want to quickly run this script without navigating to its location, you can create a desktop shortcut:
- Right-click on
switch_display.bat
and select Create Shortcut. - Move the shortcut to your desktop or any convenient location.
- (Optional) Right-click the shortcut, go to Properties, and:
- Under Shortcut → Run, select Minimized to prevent a visible command prompt window.
- Click Advanced and check Run as administrator (if needed).
- Double-click the shortcut to switch displays instantly.
Alternatively, you can assign a keyboard shortcut:
- Open Properties of the shortcut.
- Click inside the Shortcut key field.
- Press a combination like
Ctrl + Alt + D
(or another preferred combination). - Click OK to save.
Now, you can switch displays with a single shortcut key!
If the current primary display is 1
, running the script will switch to display 2
, and vice versa.
- This script assumes you have exactly two displays (
1
and2
). If your setup is different, modify the script accordingly. - Ensure the script has permission to modify
active.txt
in its directory.