Hi, Byron.
Your code returns items that do not have a certain label index before the script’s run. In the process, it gives them that label.
on run {input, parameters}
set output to {}
repeat with curItem in input
tell application "Finder"
if label index of curItem is 2 then
-- curItem's label index is 2. Ignore it.
else
-- curItem's label index is NOT 2.
-- Append it to the output list.
set end of output to curItem
-- Set its label index to 2.
set label index of curItem to 2
end if
end tell
end repeat
-- All the items that were in input now have color label 2.
-- Only items that did not have that label to start with are in output.
return output
end run
If you want instead to select items that already have label index 2:
on run {input, parameters}
set output to {}
repeat with curItem in input
tell application "Finder"
if label index of curItem is 2 then
set end of output to curItem
end if
end tell
end repeat
return output
end run
Having been able to use my Tiger machine this morning, I have to say that when try the Automator sequence you describe, the scripts above output the relevant text file aliases, but for some reason, the “Combine Text Files” action only returns an empty string. Consequently, the “Filter Paragraphs” action (at which you hinted somewhere above) doesn’t pass any text at all and the next “Run AppleScript” tries to read text that isn’t there. (As you originally suspected.) That may be a big part of the problem: the “Combine Text Files” action itself seems to be duff.
I have more success if I combine the files during the first “Run AppleScript” script instead of using the “Combine Text Files” action:
on run {input, parameters}
set output to ""
repeat with curItem in input
tell application "Finder"
if label index of curItem is 2 then
-- Concatenate the (string) text from this file to what we have already.
set output to output & (read curItem)
end if
end tell
end repeat
return {output}
end run
The “Filter Paragraphs” action goes directly after that.
If more than one paragraph gets through the filter, the next “Run AppleScript” script (the one you were asking about yesterday) will need to cope with the fact that more than one line in the text begins with “Song File Names”. At the moment, it’s only geared up for one.
The script below combines all the stages from identifying which of the files returned by the first action have label index 2 to returning the song file names. It’s a lot faster than the four individual Automator actions it replaces. I don’t know if you want the names returned as a flat list or as a list of lists of names, each list of names corresponding to a “Song File Names” line. This script returns the latter. It’s easily changed if you want a flat list.
on run {input, parameters}
set paragraphList to {}
repeat with curItem in input
tell application "Finder"
if (label index of item curItem is 2) then
-- If this text file's label index is 2,
-- append its paragraphs to those already obtained.
set paragraphList to paragraphList & paragraphs of (read curItem)
end if
end tell
end repeat
-- (A script object for speed in dealing with the paragraph list.)
script o
property p : paragraphList
end script
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
-- Filter the paragraph list.
repeat with i from 1 to (count paragraphList)
set thisPara to item i of o's p
if (thisPara begins with "Song File Names") then
-- If this paragraph begins with "Song File Names",
-- get its text from the fourth word on.
set thisPara to text from word 4 to -1 of thisPara
-- . and replace it in the list with a list of its colon-delimited text items.
set item i of o's p to thisPara's text items
else
-- Otherwise replace the paragraph with a 'missing value'
set item i of o's p to missing value
end if
end repeat
set AppleScript's text item delimiters to astid
-- Return the lists from the "paragraph" list.
return paragraphList's lists
end run