I select a file named 08252022 and hit run.
The files 08252022_A gets inserted, then 08252022_B, then 08252022_C, etc.
Since the files names have a normal convention this allows me to select all files in a folder, regardless of it being 1 or 100, and the proper files get inserted where they need to go.
Now I need to tweak it so it still does its main task but a separate file needs to get created at the end. So for example:
File 08252022_A gets inserted, then 08252022_E, then 08252022_F, then save
File 08252022_B automatically has 08252022_C and 08252022_D inserted into it and saved to a different location
My problem is that when I use the openDoc() function the "focus" is still on the first file. So inserting pages still insert them into 08252022. Not 08252022_B. Is there a way to shift focus mid execution so the files get inserted where they need to go? Or do I have to finish the action and start a new one?
When you use openDoc it returns a Document object (if successful). That object is what you need to use later on when inserting new pages, instead of the "this" keyword. If you do that it won't matter which file has the focus.
However, you'll also need to save (and close) this file in your code when done with it, as the Action won't do that for you.
Gosh I feel stupid for missing something so elementary. That is what I needed. Thank you!
Another option, maybe a better one, is to check the file-name first, then decide how to handle it.
If it ends with a number, process it like you described in the first part. If it ends with "_B", process it differently.