Error when running script through a batch action
So I’m obviously missing an important step here, but I cannot get my script to run via a batch action.
I’ve put together a script that does the following to an open file:
-names the path the same as the filename - extension
-add text frame withe contents of the filename - extension
-sends the text frame to the back
-aligns the text frame to the bottom center of the path
-hides the textframe
-groups the path and textframe together
-names the group as the filename - extension
(removed these final steps for testing:
-copies the group
-open the .ai file - All.ai
-paste group from first file in place on all.ai
-save all.ai
-close all.ai)
This script runs perfectly when I run it from File->Scripts but the second I put it into an action it doesn’t work properly. I’ve narrowed it down the the select sections that appear to be messing up.

I’ve tried the select a few different ways to try and get it to work with the action, but the multiple ways don’t seem to be working.
Select before sending the textframe to the back and align script:
// clear selection
selection = [];
// get all text frames
var textFrames = app.activeDocument.textFrames;
// grouped text frames will have a 'GroupItem' as parent
for (var i = 0; i < textFrames.length; i++) {
if (textFrames[i].parent.typename == "Layer") {
textFrames[i].selected = true;
}
}
doc.textFrames.getByName('sidepanelsOutline');
app.executeMenuCommand("sendToBack"); //Send to Back
app.activeDocument.layers["Layer 1"].hasSelectedArtwork = true; ///Select before align
script for textframe visibility and to make all objects into a group.
selection = [];
app.activeDocument.textFrames.getByName("sidepanelsOutline").selected = true;
app.executeMenuCommand("hide");
app.activeDocument.layers["Layer 1"].hasSelectedArtwork = true;
app.executeMenuCommand("group");
app.activeDocument.groupItems[0].name = docName;
I’ve tried multiple different ways to select and complete this but none seem to have worked when running the script from an action. But they work perfect just running the script by itself.
Are there certain commands (like executeCommands) that you can’t use if you are going to run the script through an action for batch work?
