Linebreak not working

Get help with using AutoHotkey and its commands and hotkeys
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Linebreak not working

07 Nov 2020, 13:03

Hi everyone!

I'm out of ideas... why is this line of code not working? It should be writing the data on seperate lines (because of the `n linebreak) but it's writing everything on one line.

What's wrong here? Thanks..

Code: Select all

fileappend,  `nDOCUMENT NAME:`n%title%`nBRUSHES USED:`n%clipboard%, C:\MyTextFile.txt
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 13:19

It worked when I tested it. Is this the entire script? Can you paste (here) the output that you see? What are the values of title and Clipboard?

Do the following commands lead to the expected output?

Code: Select all

MsgBox,, Title, #%title%#
MsgBox,, Clipboard, #%Clipboard%#
Are you using a text editor that shows carriage returns and line feeds normally?
Last edited by mikeyww on 07 Nov 2020, 13:24, edited 1 time in total.
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Linebreak not working

07 Nov 2020, 13:24

thanks mikeyww

a sample of %title% would be:
mypicture-Recovered-Recovered.psd @ 30.5% (Color, RGB/8) *

and a sample of %clipboard% would be:
Texture - Grain


are these samples somehow throwing it off?
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 13:26

Possibly, because % is a special character, so it depends on how you handle it. Try the following.

Code: Select all

title := "mypicture-Recovered-Recovered.psd @ 30.5% (Color, RGB/8) *"
Clipboard = Texture - Grain
out = C:\MyTextFile.txt
FileRecycle, %out%
fileappend,  `nDOCUMENT NAME:`n%title%`nBRUSHES USED:`n%clipboard%, %out%
FileRead, ttext, %out%
MsgBox,, Results, %ttext%
If you have * accidentally before the file name (but you did not have that in your example), you will also disable end-of-line translation, which will omit carriage returns.

Are you somehow using a Unix file, editor or display for Unix files, or Unix encoding?
Last edited by mikeyww on 07 Nov 2020, 13:36, edited 1 time in total.
User avatar
Smile_
Posts: 326
Joined: 03 May 2020, 00:51

Re: Linebreak not working

07 Nov 2020, 13:35

@scriptor2016 , Your script is working just fine for me!
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Linebreak not working

07 Nov 2020, 13:35

hmmm, I think the problem is indeed with the %title% portion. Here's a little more of what I was doing:

Code: Select all

wingettitle, title, A

out = C:\MyTextFile.txt
FileRecycle, %out%

fileappend, DOCUMENT NAME:`n%title%`nBRUSHES USED:`n%clipboard%, %out%

FileRead, ttext, %out%
MsgBox,, Results, %ttext%
and this still doesn't work. Looks like I need to somehow get %title% to be in the quotation marks, but how do I do that when it's a variable?
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 13:38

Can you show a screenshot of the message box?

What is the result of:

Code: Select all

MsgBox,, Clipboard, #%Clipboard%#
Last edited by mikeyww on 07 Nov 2020, 13:39, edited 1 time in total.
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Linebreak not working

07 Nov 2020, 13:39

edit - thanks guys!! Looks like it's working now.

But here's the issue:

I was viewing the output file in Notepad. And it shows everything written on one line.

But if I view the output file in Notepad++, it shows it on several lines. Which is very confusing. i tried Notepad with Wordwrap both on and off and same results, everything on one line. Any idea why that might be?
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 13:42

Sounds like an issue with line feeds. If you paste the text at the following Web site, you can see the control codes.

https://www.soscisurvey.de/tools/view-chars.php

I don't think that Notepad has a way to alter the display of those characters, so perhaps this Web page will be informative.

Here is how my earlier script looks at the Web page.
Attachments
image201107-1343-006.gif
image201107-1343-006.gif (5 KiB) Viewed 228 times
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Linebreak not working

07 Nov 2020, 13:50

does that mean that
mypicture-Recovered-Recovered.psd @ 30.5% (Color, RGB/8) *

contains invisible characters that Notepad cannot see, resulting in the `n linefeed to fail?
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 13:56

That would be surprising-- but the idea is to figure it out-- so if you just copy the text in your output file and paste it onto that Web page, you will be able to see everything. If you see the normal CR LF sequences, then perhaps there is some other issue at hand.
User avatar
boiler
Posts: 6629
Joined: 21 Dec 2014, 02:44

Re: Linebreak not working

07 Nov 2020, 14:01

Notepad needs both CR and LF to actually show line breaks — at least older versions did. Files with only a LF, such as those that come from MacOS, will not be shown with breaks between the lines. Windows 10 updates have supposedly changed that. Perhaps you are using an older version of Windows.
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Linebreak not working

07 Nov 2020, 14:04

Yes, I'm still on Windows7 64-bit. My motherboard is an older one and I don't think it supports Windows 10, so I'm in for a big headache when it comes time to update my system :(
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 14:05

That's helpful to know; thanks.

With EOL translation, it's not clear why line feeds would be omitted from the output, but the idea is to see if that is the case.
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 14:05

I'm also on Win7 Pro 64-bit and do not have trouble with the line feeds.

Perhaps look at the Web page?
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Linebreak not working

07 Nov 2020, 14:10

yes sorry, I looked at the page. But it's a little beyond my level of knowledge lol

I pasted the %title% and then was a little lost as to what it was doing :(
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 14:18

You have a text output file that you created. Open that file in Notepad++. Select all of the text. Press ^c to copy it to the clipboard. Go to the Web page. Paste it there, in place of the default text on that page. Click on "Show me the characters". See what is there. It will show the CR and LF symbols if they are present.
TAC109
Posts: 614
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Linebreak not working

07 Nov 2020, 16:49

@scriptor2016
Check the EOL section of FileAppend. Although it is badly worded, in essence it is saying that all `n get translated to `r`n (normal Windows end of line) unless the data already contains one or more `r`n . I suspect that in your case, somewhere in the data being appended there is already one or more `r`n.

To fix, change your FileAppend to something like this:

Code: Select all

fileappend, % StrReplace("DOCUMENT NAME:`n" title "`nBRUSHES USED:`n" clipboard,"`r"), %out%
Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
User avatar
mikeyww
Posts: 3893
Joined: 09 Sep 2014, 18:38

Re: Linebreak not working

07 Nov 2020, 17:05

Hey, that's good to know! Thank you, @TAC109.

I ran a test.

Code: Select all

FileAppend, this`nthat`nthe other`r`n, %TEMP%\test.txt
Indeed, the problem was reproduced.
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Linebreak not working

08 Nov 2020, 04:03

TAC109 , thanks!!

This actually works - Notepad now shows the text with the line breaks properly. Strange how that works. Haven't seen that problem before.

Thanks to everyone who took a look at this. It was totally baffling to me, I thought maybe it was a bug or something.

Return to “Ask For Help”

Who is online

Users browsing this forum: 20170201225639, AHKStudent, Bing [Bot], ddougal, Google [Bot] and 55 guests