Start by simplifying your macro -- if nothing else, that'll make it easier to debug!
You do a simulated-key Copy and, almost immediately, a "Copy" action. Is there a reason for that? And the "Copy" action includes a pause until the clipboard has changed before continuing the macro -- so you don't need to save the clipboard seed or do the comparison.
Why are you putting the clipboard into a variable rather than using it directly?
Now we get to the actual problem -- you're checking whether the variable Filename pattern
is empty and if it is then you fill it with your TempVariable
(which is also your clipboard contents). But Filename pattern
is a Global and it persists across executions of your macro. The very first time you ran the macro it was set to the value you copied -- every run after that is empty
is false
and so the value isn't changed.
It probably only keeps working for Composer A because Composer A was the first value ever assigned!
You next check the clipboard for your "STOP" condition, which would be better done at the top of the loop after the Copy action. (Also, "contains " is case-insensitive and doesn't mean "exactly matches" -- so you'd also cancel the macro if there was a composer named "Stoppard", which probably isn't what you want...)
You then run an AppleScript inside a Shell Script, doubling the overhead for no apparent reason, to do something that looks like "select all the items in the currently active Finder window whose name begins with the Composer name".
This looks like a good first attempt at quite a complex macro, but I can't help but feel that in trying different things to make it work you've made it over-complicated and inconsistent (and the two often go hand-in-hand). Have a go at simplifying things yourself, and if you explain what you are trying to do perhaps someone can right their own version for you to compare against.
(I know you have explained what you are doing at the top of your post, but it isn't complete. For example, "select the right file in the Finder" -- you can't do that with just a name, there needs to be an indication of where the file is. I'm assuming it's "the right file in the active Finder window", but I'm usually wrong when I guess!)