Reputation: 35933
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
Upvotes: 1
Views: 923
Reputation: 7555
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.
Upvotes: 2