Passing user input to an AppleScript in Automator

I am using an Automator workflow which includes:


“Run Applescript”.


The Applescript has two variables eg

Set Christian_Name to “Sam”

Set Surname to “Smith”


I would like to able to run the script with different user inputs to be entered concurrently


I have tried many combinations, which have included “Ask for text” but I can’t then assign the input to Christian_Name and Surname.


On Run(input, parameters)

seems to work for one input but I can’t get the two inputs from the two “Ask for text”.


I would be grateful to be shown the syntax please.

iMac 21.5″, macOS 10.13

Posted on Jun 30, 2025 07:53 AM

Reply
5 replies

Jun 30, 2025 08:35 AM in response to Need_help_give_help

I don't like how Automator throws that Ask for Text window elsewhere on the Desktop, so one can tell AppleScript to do this for you and capture given and surnames in one dialog. The key to this is using the words clause…

use scripting additions

on run {input, parameters}
	
	set {givenName, surName} to words of text returned of (display dialog "Enter name: " default answer "")
	display dialog "Given: " & givenName & return & "Surname: " & surName
	return input
end run


Jun 30, 2025 02:38 PM in response to Need_help_give_help

> seems to work for one input but I can’t get the two inputs from the two “Ask for text”.


Ask for text will always ask for a single text item. To get two variables you have to run it twice (or add some code to split the name into first and last name components).


If you have two ask for input actions, and two variables, the key to passing them to the AppleScript is to add the action:


Get Value of Variable


before the Run AppleScript action.


The value of the variable will be passed into the AppleScript's input where you can extract it for use in the script.


If you have multiple variables (e.g. your first name and last name variables), just add repeated Get Value of Variable actions and they'll be passed through in order:


Here, the Run AppleScript is preceded by two Get Value of Variable actions, so input is a list of two items which you can extract and use in the script.

Jul 1, 2025 11:36 AM in response to Need_help_give_help

Here's an entire workflow I used to test the method:


Ask for Text (require an answer)

Set Value of Variable (new variable -> first_name)


Ask for Text (require an answer, ignore this action's input)

Set Value of Variable (new variable -> last_name)


Get Value of Variable (first_name, ignore this action's input

Get Value of Variable (last_name)


Run AppleScript:


on run {input, parameters}
	
	set fn to item 1 of input
	set ln to item 2 of input
	display dialog "Hello " & fn & space & ln
	return input
end run


When run this prompts for two fields, first_name and last_name. These are then passed to the AppleScript (via two Get Value of Variable actions).


Jul 1, 2025 02:22 AM in response to Camelot

Thank you VikingOSX and Camelot.


With a bit of fiddling I have got VikingOSX’s method working.


I have tried Camelot’s method and I can get a single ‘Ask for text’ into the Applescript via ‘input’ but with all combinations (I think) of ‘Ask for text’ and ‘Get Value of Variable’ including selecting/deselecting ‘Ignore this

action’s input’ I cannot get the Applescript to recognise: ‘item 1 of input’ (and of course item 2 of input).

I suspect that nothing is getting passed to input.


Noting I have now got a method that works I do not expect Camelot to help further but I am intrigued why I can’t get his method to work. I must be doing something wrong.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Passing user input to an AppleScript in Automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.