AppleScript – Add userinput to text file

applescriptfiletext;

How can I add a user input variable to a text file?

This is what I have right now:

-- ask user 
display dialog "Enter Cheat" default answer "99 Gold, super health, unlimited Grenades.."
set cheat1 to (text returned of result)

-- create text file
    set newText to "I am now
    adding
    a few
    test lines"

 do shell script "echo " & quoted form of newText & " >> ~/Desktop/test.txt"

I want to somehow put 'cheat1' inside the text file and not come out as cheat1, but as the text the user gave

any help?

Best Answer

Try the following:

set cheat1 to the quoted form of text returned of (display dialog "Enter Cheat" default answer "99 Gold, super health, unlimited Grenades..")

set newText to quoted form of "I am now
    adding
    a few
    test lines"

do shell script "echo " & newText & " >> ~/Desktop/test.txt"
do shell script "echo " & cheat1 & " >> ~/Desktop/test.txt"

Results:

I am now
    adding
    a few
    test lines
99 Gold, super health, unlimited Grenades..