Hi everyone,
I am working on a macro that dynamically discovers a directory structure and passes absolute file paths to an external Swift script for PDF processing. I am encountering issues with variable assignment and path resolution within my nested loops.
Ellen: Genie tries many different varieties of these nested loops. I get the feeling that Genie does not understand how they work. Since some folders are absolute and others change, it is confusing.
THE WORKFLOW:
- Loop 1: Iterates through a constant parent directory to find a dynamic 'Book Folder', assigning the path to Local_BookFolder. EllenM: The book folder has a permanent path. It contains another folder which always is given the title and author of the book.

- Loop 2 & 3: Iterate through %Variable%Local_BookFolder% to identify a specific .pdf and .txt file, intended to be assigned to Local_FilePath and Local_toc respectively. Ellen: CleanTOC.txt is a permanent name. The pdf and the folder names change with different books.
- The Script: An "Execute Swift Script" action pulls these variables from the environment to process the "chunks".
THE PROBLEM:
The local variables are not resolving to the correct absolute paths. In my testing, Local_FilePath is frequently returning the parent directory path instead of the file path, or the variables are being "swapped" or lost during loop termination. I suspect my Break From Loop placement or the use of nested "If All Conditions Met" containers is causing the execution to skip the variable assignment or terminate prematurely.
TECHNICAL DETAILS & ERRORS:
Engine Log Error:
Action 100986979 failed: Execute a Swift Script failed with script error: ERROR: PDF file not found. Check if Local_FilePath is set correctly.
2026-04-20 21:29:55 Action 100986979 failed: Execute a Swift Script failed with script error: ERROR: PDF file not found. Check if Local_FilePath is set correctly
2026-04-20 21:29:55 Execute a Swift Script failed with script error: ERROR: PDF file not found. Check if Local_FilePath is set correctly. Macro “02 Chunker_w/ swift Ellen” cancelled (while executing Execute Swift Script).
Variable Debugging (Current Output from Display Window):
- Local_BookFolder: /.../TOC_container/Clinical Guide Klein
- Local_FilePath: /.../TOC_container (Incorrect - resolving to parent)
- Local_toc: /.../TOC_container/Clinical Guide Klein/BookName.pdf (Incorrect - resolving to PDF instead of TXT)
Folder: /Users/ellenmadono/Downloads/workspace_chunk/TOC_container/Clinical Guide Klein PDF: /Users/ellenmadono/Downloads/workspace_chunk/TOC_container TOC: /Users/ellenmadono/Downloads/workspace_chunk/TOC_container/Clinical Guide Klein/CLINICAL FOCUS GUIDE VOLUME 1 (LOUISE KLEIN R.S.HOM.).pdf
I have attached the .kmmacros file.02 Chunker_w- swift Ellen.kmmacros (21.1 KB) Could someone review the nesting of my If/Then containers and the Break From Loop logic to ensure the variables capture the absolute paths correctly before the script executes?
Thank you for your help!
