I've been working on a plugin function that runs a user script, and it seems to work reliably. Here's the code:
AIErr error = kNoErr;
error = sAIAction->AINewActionParamValue(¶m);
error = sAIAction->AIActionSetString(param, key1, val1.c_str());
error = sAIAction->AIActionSetString(param, key2, val2.c_str());
error = sAIAction->PlayActionEvent("adobe_commandManager", kDialogOff, param);
error = sAIAction->AIDeleteActionParamValue(param);
You can try it by adding a script named "test_script" -- either AS or JS -- to your Scripts folder. The script should show up in your File > Script menu. Also, you must have a document open before running it, or you will get an "Object 'test_script' cannot be found" error.
The wildcard here is the string val1. When I exported my recorded "Insert Menu Item" action it showed string parameter 1 as 5f3078363030303034306337663930, which translates from hex to ascii as "_0x6000040c7f90"
Two questions: Is string parameter 1 a menu item handle? That's not obvious to find via code, since the Scripts menu only populates while the user pulls up the menu. Is there a better way to retrieve this value than by exporting actions?
Question 2: When I add or remove scripts, this code continues to work for me, but does it work for others?
I'm targeting AI 23 through 27. Any comments or suggestions for improvement would be much appreciated.