Unless you select "Ignore this action's input" in #3, it will just append the selected file(s) to output from script #2 as its output, so script #4 will get them.
The problem is that you get an implicit "Conversion from Text to Files/Folders" feeding #2 into #3. So, if #2's output is a list of strings that look like pathnames but aren't, they will get converted into pathnames to files that don't exist, which will get converted into references to files that don't exist, which will just get dropped when #3's output gets converted back to text for #4.
The easy way around this (conceptually easy; it does mean a bit of extra code…) is to have script #2 store the list in a temporary file, and print out the filename. That filename will pass through the conversions and come out the other end just fine, so script #4 can open and read the file to get the list back.
To take a silly example, let's say you were doing this:
import sys
new_list = sorted(sys.argv[1:])
print '\n'.join(new_list)
Instead, do this:
import sys
import tempfile
new_list = sorted(sys.argv[1:])
with tempfile.NamedTemporaryFile('w', delete=False) as f:
f.write('\n'.join(new_list))
print f.name
Then, in script #4, instead of this:
import sys
new_list = sys.argv[1:-1]
step3 = sys.argv[-1]
… do this:
import sys
with open(sys.argv[1]) as f:
new_list = list(f)
os.remove(sys.argv[1])
step3 = sys.argv[2]
Of course in a more realistic example, you'd probably want to use, e.g., pickle.dump
instead of just '\n'.join
, but this should be enough to show the idea.