1

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?

1

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..
  • it is deleting the other text, I want to add cheat1 into text file without deleting the other text. I want to add it to a new line / new paragraph – user3316925 Jul 30 '15 at 21:35
  • @user3316925, See updated answer. – user3439894 Jul 30 '15 at 21:45

You must log in to answer this question.

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