Printing Results of dialog to printer or copying data to TextEdit

Hey everyone.

I am trying to take the data that I put together in my script in the form of a dialog and either print it or save it to a file in an understandable format.

tell application "Finder"
	
	--set Width in inches
	
	display dialog "What is the Pool's width in:" & return default answer "Feet"
	set WFeet to text returned of result
	set WFeet to WFeet * 12 as text
	display dialog "What is the Pool's width in:" & return default answer "Inches"
	set WInches to text returned of result
	set Width1 to WFeet + WInches as text
	
	--Ensure that you get a positive number
	
	if Width1 is less than or equal to 0 then
		repeat
			display dialog "Please enter a Non-Negative, Non-Zero value for Width"
			display dialog "What is the Pool's width in:" & return default answer "Feet"
			set WFeet to text returned of result
			set WFeet to WFeet * 12 as text
			display dialog "What is the Pool's width in:" & return default answer "Inches"
			set WInches to text returned of result
			set Width1 to WFeet + WInches as text
			if Width1 is greater than 0 then
				exit repeat
			end if
		end repeat
	end if
	
	--set Length in inches
	
	display dialog "What is the Pool's length in:" & return default answer "Feet"
	set LFeet to text returned of result
	set LFeet to LFeet * 12 as text
	display dialog "What is the Pool's length in:" & return default answer "Inches"
	set LInches to text returned of result
	set Length1 to LFeet + LInches as text
	
	
	--Ensure you get a positive number
	
	if Length1 is less than or equal to 0 then
		repeat
			display dialog "Please enter a Non-Negative, Non-Zero value for Length"
			display dialog "What is the Pool's length in:" & return default answer "Feet"
			set LFeet to text returned of result
			set LFeet to LFeet * 12 as text
			display dialog "What is the Pool's length in:" & return default answer "Inches"
			set LInches to text returned of result
			set Length1 to LFeet + LInches as text
			if Length1 is greater than 0 then
				exit repeat
			end if
		end repeat
	end if
	
	--Set Length and Width to feet for display purposes
	
	set Length2 to Length1 / 12 as text
	set Width2 to Width1 / 12 as text
	
	--Ensure that when someone enters the values for length and width backwards that they still get the correct result
	
	if Width2 is greater than Length2 then
		set Panels to (round Width1 / 72 rounding up)
	else
		set Panels to (round Length1 / 72 rounding up)
	end if
	
	--sets the spacing between the panels to be panels less one, in inches e.g., 14 panels, spacing equals 13
	
	set Spacing to (Panels - 1)
	
	
	set Yardage to ((Panels * Length1 + Spacing) / 36) round
	
	set WFeet to (round WFeet / 12) as text
	set LFeet to (round LFeet / 12) as text
	
	if Width2 is greater than Length2 then
		display dialog LFeet & " ft. " & LInches & " in." & " by " & WFeet & " ft. " & WInches & " in." & return & return & "The area of this pool will be " & ((Width1 * Length1 / 144) round) & " Sq. Ft." & return & return & "The number of panels for this liner will be " & Panels & return & return & "The material usage on this pool will be " & Yardage & " yds"
		
	else
		set Yardage to ((Panels * Width1 + Spacing) / 36) round
		display dialog WFeet & " ft. " & WInches & " in." & " by " & LFeet & " ft. " & LInches & " in." & return & return & "The area of this pool will be " & ((Width1 * Length1 / 144) round) & " Sq. Ft." & return & return & "The number of panels for this liner will be " & Panels & return & return & "The material usage on this pool will be " & Yardage & " yds"
	end if
end tell

(*tell application "TextEdit"
	activate
end tell
tell application "System Events"
	keystroke "v" using {command down}
end tell*)


--Script written and compiled by Brian Keith Eibert 11/14/08; rev. 11/18/08

Does anyone have any ideas on how to do this? I am not a scripter by trade, so the simplest answers would be the best :slight_smile:

Thanks, Brian

Hi,

to save the result you can use something like this


.

	set WFeet to (round WFeet / 12) as text
	set LFeet to (round LFeet / 12) as text
	
	if Width2 is greater than Length2 then
		set theMessage to LFeet & " ft. " & LInches & " in." & " by " & WFeet & " ft. " & WInches & " in." & return & return & "The area of this pool will be " & ((Width1 * Length1 / 144) round) & " Sq. Ft." & return & return & "The number of panels for this liner will be " & Panels & return & return & "The material usage on this pool will be " & Yardage & " yds"
	else
		set Yardage to ((Panels * Width1 + Spacing) / 36) round
		set theMessage to WFeet & " ft. " & WInches & " in." & " by " & LFeet & " ft. " & LInches & " in." & return & return & "The area of this pool will be " & ((Width1 * Length1 / 144) round) & " Sq. Ft." & return & return & "The number of panels for this liner will be " & Panels & return & return & "The material usage on this pool will be " & Yardage & " yds"
	end if
	display dialog theMessage
	set theFile to choose file name
end tell


try
	set ff to open for access theFile with write permission
	write theMessage to ff
	close access ff
on error
	try
		close access file theFile
	end try
end try

Thanks Stefan, I’ll try this tomorrow and let you know.

Brian

Okay, I got to it sooner than tomorrow. That works great! Thank you. Understanding why it works is another thing altogether though :slight_smile:

Perhaps you could point me to a Forum that describes that type of procedure?

If not, no worries.

Thanks again.

Brian

This forum is the right place :wink:

the variable theMessage contains the result text, which is displayed.
choose file name opens the save dialog and returns a file URL
Then the text will be written to disk with the write command of Standard Additions.
There is a extended error handling to avoid leaking open files

That’s all