Wednesday, September 22, 2021

WaitWindow - checking for open and closed windows from a batchfile

Datatalk / Waitwindow.

This is a little command line tool I wrote to help me check from a batch file for windows which are open or closed. It can also launch other programs if a specific condition is met.

I couldn't find what I needed, and so I wrote it myself... You can download waitwindow.exe and waitfile.exe here.

(Searching for wallpapers may have brought you to this page. If so, try this link for a selection from the wallpapers that I collected.)


Update

Some command line options have changed. Type waitwindow /? to see the changes.


Use

Typical usage scenario: you need to interact with some program but to do so you must wait until a certain file exists or some window is open or closed. Another use might be a script that launches ten different programs that you use for certain activities.

For example:

  • OBS
  • Excel
  • Grammarly
  • Some websites including GoogleDocs
  • Balabolka
  • Squeezebox music player
  • A music player

Also, I want to wake up my music server.

In some cases, I want to wait until a specific program / window is open, in other cases, I don't want to launch that same program again if the window is already open.


Syntax

waitwindow <windowname> [<timeout> [<action> [<commandline>]]]


Example batch file

Some parts from two different real-life batch files...

Start by loading a wallpaper.

WallX is a little wallpaper manager I wrote to handle random wallpapers on multiple monitor configurations. Of course it also works on a single monitor:-)

rem *** wallpaper

start "wallpaper" wallx load c:\googledrive\wallpapers\pk_cover_kindskisslight.jpg fade distort 10 expand 100 round keep resident


Bring up Bluetooth settings to remember to switch on the headphone late at night. For this I open the settings, wait until the window is open, then wait again until it's closed.

rem *** settings

start "bluetooth settings" ms-settings:bluetooth

waitwindow "settings*" 300 openclose


Open the browser and bring up Blogger, so I can edit this blog

Tip: use timeout 1 after launching every two URLs, this will keep the tabs in order, and could actually speed up loading pages (seriously). See if it affects you.

rem *** ninelizards

start "blog page" chrome --profile-directory=%ninelizards% "https://ninelizardsblog.blogspot.com/"

timeout 1


More browser windows. Note that I use different profiles. This one is for Wattpad.

start "wattpad" chrome --profile-directory=%angeljay% "https://www.wattpad.com/myworks"

timeout 1


A text-to-speech tool Balabolka, and of course Grammarly. Balabolka is a sloooow loader.

start "grammarly" grammarly

start "balabolka" balabolka

waitwindow "balabolk*" 300


Ah, Excel, of course...

start "plot" c:\googledrive\plot.xlsx

waitwindow "excel*" 300


Music, maestro. First wake up the music server, then launch the player, then bring up the web page of Squeezebox LMS.

WakieWakie is a little WOL tool I wrote for waking up machines on a network. 

wakiewakie.exe adapter 192.168.*.* router 192.168.0.98 server 192.168.0.6 mac xx:xx:xx:xx:xx:xx retry 1600 linger 1000 history

waitwindow "squeezeplay*" 1 ifnot squeezeplayonly.bat

waitwindow "squeezeplay*" 300

start "squeezebox lms" chrome --profile-directory="Default" "http://192.168.0.6:9000/"


OBS I only want to launch once.

waitwindow "obs*" 1 start "C:\Program Files\obs-studio\bin\64bit\obs64.exe"

timeout 1


And finally, some web pages related to my job, because I always have to work...

start "outlook" chrome --profile-directory="Default" "https://outlook.office.com/mail/inbox"

start "outlook" chrome --profile-directory="Default" "https://outlook.office.com/calendar/view/week"

timeout 1

start "google calendar" chrome --profile-directory="Default" "https://calendar.google.com/calendar/u/0/r"

start "to do" chrome --profile-directory="Default" "https://keep.google.com/u/0/#home"


To download waitwindow.exe and waitfile.exe:


You'll find all self-written tools here:


Tip: CMDOW can be used to manipulate windows, bring them to the front, activate them etc. See also here.

No comments:

Post a Comment