2

I have two monitors that I want to switch between using auto-hotkey and an IR remote. I have the IR remote running the .bat file on button press, but I can't quite figure out how to check which monitor is currently in use. So, for example, I want something like this:

@echo off

if Display is external

DisplaySwitch.exe /internal

) else (

DisplaySwitch.exe /external

)

Basically, I cannot quite figure out what the "if" command for this situation would be (admittedly not a very super user by any stretch).

Thanks for any and all help~!

2
  • 1
    Tell us about your two displays. Are they identical? Same/different resolutions, etc.? If a program could observe the current monitor's details, would there be some property of the monitors that could distinguish them? Commented Jul 12, 2017 at 2:44
  • Different sizes (20" monitor vs. 48" TV) but same resolution (1080p). One is registered as display 1, one is registered as display 2, but other than that, they are pretty similar. One Is plugged into HDMI and one is plugged into DisplayPort, but the two plugs are in the same video card. Thanks! Should I have it launch an empty program during the first switch, then check for that program, terminate it during the second switch? Commented Jul 12, 2017 at 2:54

1 Answer 1

1

If you want your batch file to always switch to the other display, it can do so by using a flag file to remember which display was last activated. Here's how:

@echo off
Setlocal
Set myFlag=c:\somefolder\monitor.flg
if Exist "%myFlag%" (
    rem flag exists. Activate internal display. Then delete flag.
    DisplaySwitch.exe /internal
    del /q "%myFlag%"
) else (
    rem flag does not exist. Activate external display. Then create flag
    DisplaySwitch.exe /external
    Echo I'm a flag for myScript.cmd>"%myFlag%"
)

Basically the script uses the existence/non-existence of the flag file as an indicator of what display it activated the last time it ran. As long as you put the flag file somewhere it cannot be disturbed, it will faithfully toggle the script's behavior between executions.

4
  • 1
    Sounds like a good idea to me. Commented Jul 12, 2017 at 3:08
  • Worked perfectly, thank you. I had something worked up where it would open/close a stickynote software when switching screens with: tasklist|>nul find /i "software.exe" if errorlevel 1 ( Your solution is so much more elegant hahaha Commented Jul 12, 2017 at 3:09
  • @secondshepherd You were certainly thinking in a profitable direction with that approach. Glad to be of help. Welcome to Super User btw. Hope you stick around. Commented Jul 12, 2017 at 3:11
  • Don't forgot to mark this answer accepted if it solved your problem. Commented Aug 9, 2017 at 21:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .