1

I have this Automator that is added as a finder service for images.

It all starts by the user selecting a bunch of images and choosing the script on the services menu.

The script then first asks the user two questions:

on run {input, parameters}
    choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform"
    set platform to the result as string

    display dialog "Choose File Name" default answer ""
    set fileName to the result as string

    // here it goes the magic line

    return input
end run

On the spot "here it goes the magic line" I want to add a line that adds platform and fileName as two entries on the array(?) of parameters (input ?) that will passed to the shell script that will follow this AppleScript.

The shell script then will have these lines:

platform=$1
shift

fileName=$1
shift

for f in "$@"; do

    // files will be processed here

I am not sure of how the shell script will receive that, but as far as I understand it is supposed to receive something like an array, composed of 3 items: the platform, the file name and the list of files selected. I understand that the shift will remove the item at the beginning of the input.

For that reason I have tried these lines:

set beginning of input to platform as string and fileName as string

and also

set beginning of input to platform
set beginning of input to fileName 
//hoping it will push platform to the second position

but none worked.

Any ideas

1 Answer 1

2

This should take care of the magic for you:

on run {input, parameters}
    set platform to (choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform") as string
    set fileName to text returned of (display dialog "Choose File Name" default answer "") as string
    set tempList to {}
    set end of tempList to platform
    set end of tempList to fileName
    repeat with i from 1 to count of input
        set end of tempList to item i of input
    end repeat
    copy tempList to input
    return input
end run

This too works, I just tested it:

on run {input, parameters}
    set platform to (choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform") as string
    set fileName to text returned of (display dialog "Choose File Name" default answer "") as string
    set beginning of input to fileName
    set beginning of input to platform
    return input
end run

Note that this is just example code and does not employ any error handling.

I believe in this use case you need to add the items to the list one at a time.

Sign up to request clarification or add additional context in comments.

1 Comment

@SpaceDog, Since you had said you also tried set beginning of input to platform I didn't bother testing and just took the reverse course. That said though, I just tested set beginning of input to fileName followed on the next line by set beginning of input to platform and it worked for me. The result was {"iPhone", "hello world", alias "Macintosh HD:Temp:image file 2.png", alias "Macintosh HD:Temp:imagefile1.png"}. Then the Run Shell Script worked with it as expected. Not sure why it didn't work of you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.