kakyo
kakyo

Reputation: 11580

AppleScript editor does not let me include line break literals in a script

I try to save my code with this line:

my write_to_file("\n", listFile, true)

in the AppleScript editor. It has to be saved as a binary script to be used as an external module.

But whenever I hit Save, the editor decide to replace the \n with line break in the script and the input arg is replaced with a blank.

I tried to replace the literal with "\n", but then it simply does not break the lines of that generated text file. I can make it work when the script is saved else where as a text file, but simply can't do the same with the AppleScript editor.

I found no online tips about this. Please help.

Upvotes: 1

Views: 1793

Answers (3)

Simon White
Simon White

Reputation: 736

Backslash is an escape character in AppleScript, so if you want to use a backslash, you have to escape it with another backslash, like so:

my write_to_file("\\n", listFile, true)

Upvotes: 0

adayzdone
adayzdone

Reputation: 11238

The alternative to return is linefeed.

Upvotes: 1

kakyo
kakyo

Reputation: 11580

Figured it out myself.

I had to replace the literal with the reserved keyword return:

my write_to_file(return, listFile, true)

Upvotes: 1

Related Questions