Display Dialog: three variables from one input screen?

Hi,

I’m a newbie trying to have a user input three integer variables into a “display dialog” screen. I have not found any reference for a “display dialog” function that can do this.

Basically, I want to have a dialog window appear that has three separate text fields that the user has to enter numbers into (similar to the way that Windows Users have to enter their Code-Key when registering their software).

Each input field will be assigned to a separate variable that I can then manipulate and use in my script.

Any suggestions would be greatly appreciated.
Thanks in advance

Model: PowerBook G4
AppleScript: 2.0.1
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)

This article is the best place to start. Go through the examples there, and see if it gets you any closer to your goal, then post back (or create a new thread) with any other questions.

Good luck,

Hi,

you can’t do this with plain AppleScript, but you could do it with AppleScript Studio,
by writing an application with a custom dialog window. This applications is also scriptable

Or use one dialog and extract the answers (no error checking in the example):

set Ans to text returned of (display dialog "Please enter 3 integers separated by commas without spaces" default answer "1,2,3")
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set tParts to text items of Ans
set AppleScript's text item delimiters to tid
set {Int_1, Int_2, Int_3} to tParts

Thank you Adam, Stephan, and Craig,

All great suggestions to help me learn how to solve my problem. The best option for me was to use the Delimiter trick since I am trying to see if a CAS (Chemical Abstract Service) number that a person types in is formatted properly. CAS numbers have a total of ten digits, separated by 2 dashes (0000000-00-0). The last digit is simply a “check digit” that is calculated using a simple formula. For example, the CAS number for water is “7732-18-5”. The “5” on the end comes from this math: (8×1 + 1×2 + 2×3 + 3×4 + 7×5 + 7×6) = 105; the last digit of 105 is “5” so the CAS number “7732-18-5” is correct.

This script allows the user to input a number separated by dashes and it checks to see if the candidate number meets the CAS Criteria.

Thanks again for all of your help and let me know if you see anything in my script that can be changed to make it more efficient since I’m a newbie…


-- Ask user to input the Candidate CAS number...
set CAS_candidate to text returned of (display dialog "Please enter a CAS number (including dashes)" default answer "0007732-18-5")
set CAS_number_test to true
repeat while CAS_number_test
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "-"
	set CAS_deliniated to text items of CAS_candidate
	set AppleScript's text item delimiters to oldDelimiters
	set {CAS7, CAS2, CAS1} to CAS_deliniated
	set CAS_trunk to CAS7 & CAS2
	
	-- Validate "check diget" of CAS number
	set CAS_trunk_count to number of text items in CAS_trunk
	set checksum to 0
	set Loop_sum to 0
	set INC_counter to 1
	set LOOP_test to true
	repeat while LOOP_test
		set Loop_sum to (item CAS_trunk_count of CAS_trunk) * INC_counter
		set INC_counter to INC_counter + 1
		set CAS_trunk_count to CAS_trunk_count - 1
		set checksum to checksum + Loop_sum
		if CAS_trunk_count is equal to 0 then
			set LOOP_test to false
		end if
	end repeat
	set checksum_text to checksum as text
	
set CAS1_test to character -1 of checksum_text
	
	if CAS1_test is not equal to CAS1 then
		beep
		set CAS_candidate to text returned of (display dialog "\"" & CAS_candidate & "\" " & "is not a valid CAS number.  Please try again" default answer "0007732-18-5")
	else
		set CAS_number_test to false
	end if
end repeat

Model: PowerBook G4
AppleScript: 2.0.1
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)

I did not mess with your analysis, just a couple of areas to reduce the total line number:


-- Ask user to input the Candidate CAS number...
set CAS_candidate to text returned of (display dialog "Please enter a CAS number (including dashes)" default answer "0007732-18-5")
set CAS_number_test to true
repeat while CAS_number_test
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "-"
	set {CAS7, CAS2, CAS1} to text items of CAS_candidate --you don't need an intermediate variable here
	set AppleScript's text item delimiters to oldDelimiters
	set CAS_trunk to CAS7 & CAS2
	
	-- Validate "check diget" of CAS number
	
	set {CAS_trunk_count, checksum, Loop_sum, INC_counter, LOOP_test} to {(CAS_trunk's length), 0, 0, 1, true} --This is a quick and easy method to set up all of your beginning values on a single line
	repeat while LOOP_test
		set Loop_sum to (item CAS_trunk_count of CAS_trunk) * INC_counter
		set INC_counter to INC_counter + 1
		set CAS_trunk_count to CAS_trunk_count - 1
		set checksum to checksum + Loop_sum
		if CAS_trunk_count is equal to 0 then
			set LOOP_test to false
		end if
	end repeat
	set checksum_text to checksum as text
	
	set CAS1_test to character -1 of checksum_text
	
	if CAS1_test is not equal to CAS1 then
		beep
		set CAS_candidate to text returned of (display dialog "\"" & CAS_candidate & "\" " & "is not a valid CAS number.  Please try again" default answer "0007732-18-5")
	else
		set CAS_number_test to false
	end if
end repeat

You can do similar things within your testing loop to cut it down even more, but it would be harder to follow the logic.