Henk Straten
Henk Straten

Reputation: 1447

Insert a rule to a script on a new line

I wrote the following script that asks for input and then writes this to a file.

^1::
 InputBox, text, fire writing, What did you achieve today?
 file := FileOpen("log.txt", "w")
 file.write(text) 
 file.Close()

return

This works. However, Im looking for two other things:

A B

Any comments on how I should change this code to achieve this?

Upvotes: 0

Views: 105

Answers (2)

Yane
Yane

Reputation: 837

For writing one liners you can also use the FileAppend command.
You can add new lines to the text by using `n

^1::
     InputBox, text, fire writing, What did you achieve today?
     FileAppend, %text%`n, log.txt
 return

Upvotes: 0

Relax
Relax

Reputation: 10543

  • Flag "w" creates a new file, overwriting any existing file.

  • Use "a" (Append) to append text to a file, creating the file if it didn't exist.

  • Once the file is opened in append mode, use file.Write(text "n") to add a new line after appending the text:

This way:

^1::
     InputBox, text, fire writing, What did you achieve today?
     file := FileOpen("log.txt", "a")
     file.write(text "`n") 
     file.Close()
 return

Upvotes: 0

Related Questions