Using dictionary/Lines collection variables with If Then Else conditions

Hi all,

Apologies for the delayed update, have had work and life get in the way. Thank you everyone for your attempts to help with this! I really appreciate it, even if I’m totally barking up the wrong tree with how I’m attempting (or explaining) this - I’m definitely more flowery wordsmith than anything else :slight_smile:

To hopefully clarify (although it *is* complex, and IANAC so I'll try my best): my goal is to create a sequence to keep Finder tabs with certain parent folders grouped together within one Finder window; and keep tabs that don't have any of these parent folders grouped in another window.

This will allow me to have open and navigate multiple tabs in one project folder, in one window, without multiple tabs open to the same path, or multiple windows hiding behind each other.

This sequence ultimately:

a. checks if any open Finder tab's title either matches the target file path, starts with it, or begins with any of a specified list of parent folder paths (e.g. '/Volumes/Creative'), brings any positive matches to the front, and (if it doesn't already exist) opens the target path as a new tab in that existing window;

b. opens a new window if there are no positive match tabs already open.

There are many conditions for how a Finder tab should be opened, depending on if a tab for the target path is already open elsewhere, if it’s at the front of Finder tabs or not; or if a tab starting with the target path is open, front of Finder tabs etc. But ‘open target path only in Finder window containing other specific tabs’ is basically the gist.

Once all this is done and the target folder path is open: a Rectangle keyboard shortcut is run to reposition the window. (I'm not using the KM Window positioning tools at all due to the MacOS bug, which has thwarted macros for me elsewhere :frowning:)

Because the whole thing is reasonably enormous, I'm looking to use categorised simple text files, read in as variables, to provide:

  1. the target file paths (to populate the prompt lists);

  2. the values of file path parent folders, which the target folder's Finder window should be grouped with.

I've totally rewritten the whole routine from scratch, and - 9 subroutines later! - I think I'm getting somewhere. However, I'm still struggling with how to search each open Finder title collection line (pulled in via Applescript and formatted into a List collection using Regex), to see if it starts with the value of any line in my parent paths lines collection.

Essentially: this, but using simple text files and Lines collections to provide the values, instead of hard-coding the values into an If/Then action.

Example of previous If/Then action

The following is my current solution, but results in too many false positives *and* false negatives:

Current For Each action checking for Finder windows starting with specified parent paths

What I think I need is a version of the solution suggested here by @peternlewis. However, whenever I try to put this into a For Each action that checks each Finder windows collection line for each parent folder collection line, the whole thing just seems to end up as an endless nest of For Each actions. And, obviously, not a working nest.

How might I go about this, please?