Save user input from Dialog box to text fiel

Hi everyone,

I am trying to write a script that will ask the user a series of questions and then save their response to a text file. For example, I would like to ask what their name is and then have their answers saved to a file.

set x to display dialog “Please Enter your Name” default answer “”

Thanks,
Jal

Hi

try this, it creates a new text file on desktop and appends the entered text to this file each time the script runs


set x to text returned of (display dialog "Please Enter your Name" default answer "")

set targetFile to ((path to desktop as text) & "writeTofiletest.txt")
set ff to open for access file targetFile with write permission
write x & return to ff starting at eof
close access ff

That worked. Thanks for all your help.

something like this?

set Questions to {"Name?", "Rank?", "Serial Number?"}
set answer to ""

repeat with i from 1 to count of Questions
	
	set answer to answer & "
" & (item i of Questions) & ¬
		": " & text returned of (display dialog (item i of Questions) default answer "")
	
end repeat
set answer to (characters 2 thru (length of answer) of answer) as text


--    "Name?: Me
--    Rank?: Yes, especially if I don't bathe.
--    Serial Number?: Tony Tiger 237"


I have modified the script to ask a few more question and retrieve the system info from the computer. I would like to also get the mac address for the Lan and wifi card and then save it to the same file. I found the script below but still having a hard time getting it to save to the same file.

set ethernet_MAC_add to do shell script “ifconfig en0 | grep ether | cut -c 8-24”
set airport_MAC_add to do shell script “ifconfig en1 | grep ether | cut -c 8-24”
return {ethernet_MAC_add:ethernet_MAC_add, airport_MAC_add:airport_MAC_add}

set xn to text returned of (display dialog “Please Enter your Name” default answer “”)

set xe to text returned of (display dialog “Please Enter your Email” default answer “”)

set xd to text returned of (display dialog “Please Enter your Dept” default answer “”)

set xb to text returned of (display dialog "Please Enter your Building " default answer “”)

set xr to text returned of (display dialog “Please Enter your Room Number” default answer “”)

set xC to text returned of (display dialog “Do you have a Workstation or Laptop” default answer “”)

set xs to text returned of (display dialog “What is your supervisor’s name” default answer “”)

set xse to text returned of (display dialog “What is your supervisor’s Email” default answer “”)

set D to do shell script “system_profiler SPHardwareDataType> $HOME/Desktop/invmac.txt”

set targetFile to ((path to desktop as text) & “invmac.txt”)
set ff to open for access file targetFile with write permission
write xn & return & xe & return & xd & return & xb & return & xr & return & xC & return & xs & return & xse to ff starting at eof

close access ff

try this:


property titleList : {"Name", "Email", "Department", "Building", "Room Number", "Computer", "supervisor's name", "supervisor's Email"}
property parameterList : {"Please Enter your Name", "Please Enter your Email", "Please Enter your Dept", ¬
	"Please Enter your Building", "Please Enter your Room Number", "Do you have a Workstation or Laptop", "What is your supervisor's name", "What is your supervisor's Email"}

set targetFile to ((path to desktop as text) & "invmac.txt")
set ff to open for access file targetFile with write permission
repeat with i from 1 to count parameterList
	try
		if i is 6 then
			set x to button returned of (display dialog (item i of parameterList) buttons {"Cancel", "Workstation", "Laptop"})
		else
			set x to text returned of (display dialog (item i of parameterList) default answer "")
		end if
		write item i of titleList & ": " & x & return to ff starting at eof
	on error
		close access ff
		return
	end try
end repeat
write (do shell script "system_profiler SPHardwareDataType") & return to ff starting at eof
write "MAC-Address Ethernet: " & (do shell script "ifconfig en0 | grep ether | cut -c 8-24") & return to ff starting at eof
write "MAC-Address Airport: " & (do shell script "ifconfig en1 | grep ether | cut -c 8-24") & return to ff starting at eof
close access ff