Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ywickham

macrumors newbie
Original poster
Jul 20, 2017
2
0
I'm creating an automator script that copies files from one folder to another and then runs an AppleScript to rename the file by splitting via delimiter and resaving with the second item. For example, using file names of:

a new file$SG789.jpg
file_2$123-456.jpg
file_name$LG123.jpg
this_file$558-432.jpg

I'm trying to split the filename by the "$" dollar sign to create the following new files:

SG789.jpg
123-456.jpg
LG123.jpg
558-432.jpg

However, when I run the script, I get the following error:

The action “Run AppleScript” encountered an error. Can’t get item 2 of alias "Macintosh HD:Users:downloads:Archive:a new file$SG789-PROC.jpg".

This is the code I'm running in the Run AppleScript workflow:

Code:
on run {input, parameters}
    set AppleScript's text item delimiters to "$"
    repeat with anItem in input
        set fileName to item 2 of anItem
        return fileName
    end repeat
end run

What am I doing wrong?
 

Red Menace

macrumors 6502a
May 29, 2011
584
231
Colorado, USA
The error message is telling you that your items are aliases, not text. You also have to actually get the text items, so your script would look something like:

Code:
on run {input, parameters}
    set output to {} -- this will be the output
    set tempTID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "$"
    repeat with anItem in input
        set namePieces to text items of (anItem as text)
        set the end of output to item 2 of namePieces
    end repeat
    set AppleScript's text item delimiters to tempTID
    return output
end run
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.