I am trying to use several lines of Javascript to construct some Visual Basic that will run a series of actions in Adobe InDesign 2022.
The actions I would like to emulate are:
- Click on Edit
- Click on Keyboard Shortcuts
- Click on Set
- Select a keyboard shortcut named [TMG]
- Click OK
This currently works using the below code on Adobe InDesign CS6, but I cannot get this to work in Adobe InDesign 2022:
try {
var myVBScript;
myVBScript = "Set w = CreateObject(\"WScript.Shell\")";
myVBScript = myVBScript + "\n";
myVBScript = myVBScript + "w.AppActivate(\"Adobe InDesign CS5.5\")";
myVBScript = myVBScript + "\n";
myVBScript = myVBScript + "w.SendKeys(\"%e\")";
myVBScript = myVBScript + "\n";
myVBScript = myVBScript + "w.SendKeys(\"h\")";
myVBScript = myVBScript + "\n";
myVBScript = myVBScript + "w.SendKeys(\"[TMG]\")";
myVBScript = myVBScript + "\n";
myVBScript = myVBScript + "w.SendKeys(\"{ENTER}\")";
myVBScript = myVBScript + "\n";
app.doScript(myVBScript,ScriptLanguage.visualBasic);
} catch (myErrorMessage){
alert('Could not apply keyboard shortcuts');
}
Any idea is this will be possible? I think the part I'm struggling with is the AppActivate. I cannot get seem to give focus to Adobe InDesign 2022 to then click on the Edit menu... Possibly because there is no 'title' or 'name' bar when the app is running.
I think it might be possible to do this by finding the process ID in task manager, but this would mean the process ID must always be the same, so could be tricky? Any thoughts?
Many thanks.