Skip to content

Text Fields

The --textfield option let you specify an area where the user can enter in some text before dismissing the dialog

It takes a parameter as text and uses that parameter as the textfield label both in the dialog UI and in reporting output

The results are sent to stdout when dialog exits in the following format:

<textfield text> : <user input>

or if using the --json option to enable json output:

{
"<textfield text>" : "<user input>"
}

If using the following dialog:

dialog --textfield "Textfield 1"

Will display the following dialog:

image

The user enters in a response:

image

which will result in the following output:

Textfield 1 : This is what the user entered

or when using --json

{
"Textfield 1" : "This is what the user entered"
}

Multiple textfields can be specified by adding additional --textfield options when calling dialog

e.g. dialog --textfield "Textfield 1" --textfield "Textfield 2"

image

You can specify as many textfialds as you need. Each textfield will output as a seperate field in the output.

You may need to adjust the --height of your dialog window if you are adding multiple textfirlds so they fit

Example:

dialog --textfield "First Name" --textfield "Surname" --textfield "Age" --textfield "Favourite Colour"

results in the following output:

First Name : Joe
Surname : Bloggs
Age : 32
Favourite Colour : Red

--json

{
"First Name" : "Joe",
"Surname" : "Bloggs",
"Age" : "32",
"Favourite Colour" : "Red"
}

Modifiers are appended to the textfield label as comma-separated values:

Terminal window
--textfield "<label>,<modifier>,<modifier>=<value>"
ModifierDescription
name=<text>Use this value as the output key instead of the label
requiredField must be filled before swiftDialog will exit
secureHide input as it is typed (password field)
passwordfillEnable macOS password autofill on a secure field
prompt="<text>"Placeholder text shown inside the field (not returned in output)
value="<text>"Pre-populate the field with a default value (editable)
regex=<pattern>Require field content to match the regular expression
regexerror=<text>Custom error message shown when the regex is not satisfied
editorMulti-line text editor instead of a single-line field
isdateReplace the text field with a date picker. Output is formatted as a short date string.
fileselectAdd a Select button that opens a file picker
filetype=<types>Restrict the file picker to the specified types (space-separated). Use file extensions (e.g. png jpg) or the type keywords folder, image, movie, video, audio.
path=<path>Set the initial directory for the file picker
confirmAdd a confirmation field whose content must match the primary field

name=<text> replaces the label as the key in output. Useful when you want a friendly label but a cleaner key name in the output.

secure hides input as it is typed, and shows a lock icon. Content is still returned as plain text on stdout.

Terminal window
--textfield "Password,secure"

image

passwordfill enables the macOS password autofill feature. Must be combined with secure.

Terminal window
--textfield "Password,secure,passwordfill"

required prevents swiftDialog from exiting until the field has a value. Required fields are marked with an * and highlighted when the user attempts to dismiss without filling them in.

Terminal window
--textfield "Full Name,required"

image

prompt="<text>" shows placeholder text inside the field. The text disappears once the user starts typing and is not included in the output. Not supported on secure fields.

Terminal window
--textfield "Name,prompt="Enter your full name""

image

value="<text>" pre-populates the field with a default value that the user can edit.

Terminal window
--textfield "Default Value Test",value="Some default value"

image

regex=<pattern> requires the field content to match the regular expression before swiftDialog will exit. regexerror=<text> sets the message shown when the pattern is not matched.

Unless the pattern explicitly allows it, a regex field cannot be empty.

Terminal window
--textfield "Product Code",prompt="Enter 5 digit code",regex="\d{5}",regexerror="Must be a five digit number"

image

Use --textfieldlivevalidation to show a green/red overlay on the field as the user types, giving immediate feedback on whether the regex is satisfied.

editor presents a larger, multi-line text area instead of a single-line field.

Terminal window
--textfield "Notes,editor"

image

isdate replaces the text field with a macOS date picker. The selected date is returned as a short date string (e.g. 3/24/2026).

Terminal window
--textfield "Start Date,isdate"

fileselect adds a Select button that opens a standard file picker. The chosen path is placed into the field and returned in the output.

Terminal window
--textfield "Config File,fileselect"

Use filetype to restrict what can be selected. Values are space-separated and can be file extensions or type keywords:

ValueSelects
folderDirectories only
imageAny image type
movie / videoAny video type
audioAny audio type
<extension>Files matching that extension (e.g. png, pdf)
Terminal window
--textfield "Select an image,fileselect,filetype=png jpg"
--textfield "Select a folder,fileselect,filetype=folder"

Use path=<path> to set the directory the file picker opens to:

Terminal window
--textfield "Log File,fileselect,path=/var/log"

image

confirm adds a second field below the primary one. Both fields must contain the same value before swiftDialog will accept the input. Useful for password confirmation.

Terminal window
--textfield "Password,secure,required,confirm"
Screenshot 2024-05-19 at 5 03 46 PM

Modifiers can be combined freely (where compatible):

Terminal window
--textfield "<label>,secure,required,prompt="<prompt_text>""
--textfield "<label>,required,regex="\d{5}",regexerror="Five digits required",prompt="00000""
--textfield "<label>,fileselect,filetype="jpeg jpg png",path=/Users/Shared"
{
"textfield" : [
{"title" : "<label>", "required" : true, "secure" : true, "prompt" : "<prompt_text>"},
{"title" : "<label>", "editor" : true},
{"title" : "<label>", "fileselect" : true, "filetype" : "png jpg"},
{"title" : "<label>", "isdate" : true},
{"title" : "<label>", "regex" : "\\d{5}", "regexerror" : "Five digits required"},
{"title" : "<label>", "secure" : true, "confirm" : true}
]
}

Pressing Return in any single-line text field triggers the Button 1 action, equivalent to clicking the default button. This does not apply to editor fields.