0

I have an Automator Application that I would like to ask the user to enter a time of the user's choosing.

Ideally, I would like the dialog box to have three fields:

1) Hour field

2) Minutes field

3) Period (p.m. or a.m.)

Fields one and two are enterable by the user and there is a colon in between the two fields. Field three is a simple drop-down list and the user must select one of the two options.

I would also like the AppleScript to check that whatever text is typed in the hour and minutes fields comports to the standards of time, and if it does not, then an error message is presented and the user must enter the text again. (I.e., the text entered in the first field must be a single-digit number between 1 and 12 and the text entered in the second field must be a two-digit number between 00 and 60.)

I know that all of this can be accomplished in three separate dialog boxes, but I really would prefer to have it all completed in one dialog box (for the sake of presenting the user with a convenient UI).

I am not very proficient in AppleScript, so this project is extremely ambitious for me. Can this be accomplished in AppleScript?

If this behavior is not possible AppleScript, can someone recommend a similar alternative language in which this kind of dialog box is possible?

Thank you.

1

It can't be done in AppleScript.

However, I did find this workaround, where text entered on each line of one field is interpreted as a separate answer:

-- multiple input dialog

on run -- example
    set {firstName, lastName} to (inputItems for {"• First Name", "• Last Name"} with title given prompt:"Enter the following items separated by a carriage return:")
    display dialog "First Name:  \"" & firstName & "\"" & return & "Last Name:  \"" & lastName & "\""
end run

to inputItems for someItems given title:theTitle, prompt:thePrompt
    (*
    displays a dialog for multiple item entry - a carriage return is used between each input item
    for each item in someItems, a line of text is displayed in the dialog and a line is reserved for the input
        the number of items returned are padded or truncated to match the number of items in someItems
    to fit the size of the dialog, items should be limited in length (~30) and number (~15)  
        parameters -        someItems [list/integer]: a list or count of items to get from the dialog
                        theTitle [boolean/text]: use a default or the given dialog title
                        thePrompt [boolean/text]: use a default or the given prompt text
        returns [list]:     a list of the input items
    *)
    if thePrompt is in {true, false} then -- "with" or "without" prompt
        if thePrompt then
            set thePrompt to "Input the following items:" & return & return -- default
        else
            set thePrompt to ""
        end if
    else -- fix up the prompt a bit
        set thePrompt to thePrompt & return & return
    end if

    if theTitle is in {true, false} then if theTitle then -- "with" or "without" title
        set theTitle to "Multiple Input Dialog" -- default
    else
        set theTitle to ""
    end if

    if class of someItems is integer then -- no item list
        set {theCount, someItems} to {someItems, ""}
        if thePrompt is not "" then set thePrompt to text 1 thru -2 of thePrompt
    else
        set theCount to (count someItems)
    end if
    if theCount is less than 1 then error "inputItems handler:  empty input list"
    set {theItems, theInput} to {{}, {}}

    repeat theCount times -- set the number of lines in the input
        set the end of theInput to ""
    end repeat
    set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
    set {someItems, theInput} to {someItems as text, theInput as text}
    set AppleScript's text item delimiters to tempTID

    set theInput to paragraphs of text returned of (display dialog thePrompt & someItems with title theTitle default answer theInput)

    repeat with anItem from 1 to theCount -- pad/truncate entered items
        try
            set the end of theItems to (item anItem of theInput)
        on error
            set the end of theItems to ""
        end try
    end repeat
    return theItems
end inputItems

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .