Split into loop method from Automator.run