ModifyGraph flags to allow modification of multiple windows

I often have two or more graphs that I want to alter in exactly the same way with ModifyGraph (mainly from the command line, not in a function). It would be great to have a new flag (or two) to allow this. For years, I have been using a procedure of my own to do this (included at the bottom of this post for clarity). That has a major downside that there is no syntax checking of the command that I want to run until it executes.

The new flags I propose are:

/N=numWins where numWins is the number of windows, starting from the top of the window stack, on which the ModifyGraph command is to be run. the /W flag would cause this flag to be ignored. /N=1 in the absence of the /W flag would behave as ModifyGraph does now.

/WINS=matchStr where the modifygraph command will be repeated on any windows whose name matches matchStr. The /N flag can be used in conjunction in order to run the command on a specified number of top-most matching windows.

There are other procedures that would benefit from similar flags (ModifyImage, ModifyTable, etc.), but it would be most useful for ModifyGraph, at least the way I use Igor. 

 

function disp_general(cmdStr,listOfMatchStrs,numGraphs[printWinN])
	String cmdStr //command to run on window
    String listOfMatchStrs //semi-colon delimited list of match strings that specify the window names to run the cmdStr on
    Variable numGraphs //number of matching graphs (starting from top-most in the experiment) to run the cmdStr on
	Variable printWinN		//optionally pass and use %s in cmdStr where window name should go, suppresses bringing window to top
	
	if (strlen(listOfMatchStrs) < 1)
		listOfMatchStrs = "*"		//default to all graphs
	endif	
	
	String list = text_matchesToListOfMatchStrs(winlist("*",";","WIN:1"), listOfMatchStrs) //returns matching window names
	Variable doPrintWinN=!ParamIsDefault(printWinN) && printWinN
	
	STring finalStr		//only for doPrintWinN
	Variable i,numWins=min(numGraphs,itemsinlist(list)); String winN;
	for (i=0;i<numWins;i+=1)
		winN = StringFromList(i, list)
		if (strlen(winN) < 1)
			continue
		endif
		
		if (doPrintWinN)
			sprintf finalStr,cmdStr,winN
			Execute finalStr
		
		else
			Dowindow/F $winN	//bring to front
			if (strlen(cmdStr) > 0)
				Execute cmdStr
			endif
		endif
	endfor
	dowindow/H/F //send the command window back to the top of the desktop.
end