Free Function Friday Ep.3 – runMenuCmd

October 09th 2015 08:00:12am

Hi there and welcome to Free Function Friday. So, are you looking for an easy way to just simply launch a menu command? Like “New Comp from Selection”, or “Split Layer”, or “Track in mocha AE”.

While not an officially endorsed method by Adobe, the executeMenuCommand() and findMenuCommandID() methods can come in handy sometimes. It certainly comes across as an easy solution, but I wouldn’t solely depend on this method if you plan on producing any public or professional scripts.

Since this method is not an officially supported feature of ExtendScript, it can and will break on you sometimes, so be forewarned. When assembled though, the two methods can make it as easy as typing in the menu name to launch said menu item. This is handy for some off beat menu items like the ones I mentioned above since they are not easily scriptable natively.

In this episode we build a function that will allow you to simply call one line of code:

runMenuCmd("INSERT_MENU_COMMAND_HERE")

/* Examples of triggering the Purge all memory command */
//Option 1 - Using the menu name
runMenuCmd("All Memory & Disk Cache...")

//Option 2 - Using the ID number
runMenuCmd(10200)

By simply placing the menu name or the command ID number in as an argument you can run this function numerous times easily within your script. Now if you are unfamiliar with After Effects Menu Command ID’s, then you should head over to an older post I made and download the free PDF that has many of the command ID’s that are available. This document is not updated often so newer versions of After Effects may have menu items not in this PDF.

Source Code:

runMenuCmd(cmd);

/*	TESTING ABOVE	*/

function runMenuCmd(cmd){
	if(cmd != null || cmd != "undefined" || cmd != " " || cmd != "  "){
		var id = app.findMenuCommandId(cmd);
		if(id != 0){
			return app.executeCommand(id);
		}
	}
}
Checkout more:
Free Function Friday Ep.38 – getMaskPaths
Houdini Mardini Beach
Expression Shorts Swinging Motion Part 1
Free Function Friday Ep.37 – getLabelColorNames
Houdini Mardini River