Cyndi, without seeing the whole code, I cannot be 100% sure, but here are some things to check out:
- was the material selected as a background or foreground?
- and then was it applied as background or foreground?
Often, when a script pulls the first pattern in the folder it is because it does not find the material in question. This is happening a lot in my scripts if patterns are included and the user forgets to put them in the Patterns folder.