Benches macOS

3

Automator Applescript get last character …

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I've got one last thing I'm trying to get working in an Automator action and I was hoping I could get some help. I've got users entering in their employee ID numbers and I need to grab the last number in the string but I get an error from the AppleScript. The error I'm getting is "Can’t make last text item of «script» into type Unicode text." Everything else works if I stub out the AppleScript, it's just this part of the action that isn't working. So I understand that the input being passed by Automator is something that AppleScript doesn't like. Is there some other way of doing this? FYI the employee ID number is all numbers, no letters if that helps.

Here's the code I'm using (I've intentionally obfuscated the stuff in between the quotes):

on run {input, parameters}

return "something" & (the last text item of input) & ".servername.edu"

end run

3 replies

Sign in or join Beachball Help to reply.

  1. 0

    V.K.

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    this means that the input of the action is not text.

    what exactly is passed by the previous action to this one. in the previous action click on the results tab and then click on {} tab. what exactly do you see there?

  2. 0

    DavidAndrus

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    The result that it shows is:

    {"whatever the user typed in"}

    A little clarification - after the user types in their ID I set a variable to that input, that variable is then passed to the AppleScript that I'm trying to use to get the last character. The reason for this is that the last number of the ID is used to determine which server the user should connect to. That action passes the server name to the next action which is a connect to server action. The purpose of the above mentioned variable is so that it will automatically connect to the server using their employee ID. If there is a better way of doing this I'm all ears.

  3. 0

    V.K.

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    try modifying the apple script action as follows

    on run {input, parameters}

    return "something" & (the last text item of ((item 1 of input) as text) & ".servername.edu"

    end run