Escape \n

Endercraft

Moderator (& bug finder :D)
Hi,
Is it possible to make something like \\n to escape \n ? Everytime I try using it it just gets turned into a newline.
It would be great to also have this for every magic text.
 

Endercraft

Moderator (& bug finder :D)
$\n
#\n
~\n~
`\n`
There are lots of possibilities to this.

What I was trying to do is to replace newlines by \n.
When you modify JSON and variables have newlines they are written as \n, except when you do stuff to it with MacroDroid it is automatically evaluated. So I was trying shell script but MacroDroid's shell doesn't really like stuff like pipes. So I guess I can use a Termux script for the moment.
I have a workaround to write it in a variable but it is automatically evaluated when used.
 

Dimlos

Well-known member
How about this kind of workaround?
 

Attachments

  • Macro.jpg
    Macro.jpg
    267 KB · Views: 19
  • Sample_Macro.macro
    1.5 KB · Views: 3

Endercraft

Moderator (& bug finder :D)
My original goal was to write \n in a file, which is not that easy.. Storing \n in a variable is easy compared to that.
 

Dm114

Well-known member
My original goal was to write \n in a file, which is not that easy.. Storing \n in a variable is easy compared to that.
No it's not so easy. It's the reason why I store \¶ in files when necessary and then, at retrieve time, replace all \¶ by \n
 

Endercraft

Moderator (& bug finder :D)
Apparently I can't get it to work with Termux either.. When launching the script from Termux everything is fine but when launching from Termux:Tasker it just doesn't work under any circumstances...
I've completely given up on MacroDroid's shell script.
 

Endercraft

Moderator (& bug finder :D)
Here's my script.
$1 should be the path to file (passed as argument).
You can create a macro (or text) and add a newline in a variable.
If you execute it from Termux it works but not from Termux:Tasker.
 

sampleuserhere

Active member
IMHO, It's better for Macrodroid to stop automatically converting "\n" into new line and start accepting new line in every field instead.

It'll break everyone's setup, but man, I can't imagine having to escape "\n". It'll another similar problem in the future.

I wonder if the Dev have ever said something about this matter? I'm kind of new here.
 

Dimlos

Well-known member
I prepared a simple script to verify this.
I found that the backslash was lost when passing the argument as is, so I enclosed it in double quotation marks.
I used double quotes in Termux.Tasker as well, and got the same output as Termux.
If you want to recognize newlines, use the -e option of echo.
 

Attachments

  • script.jpg
    script.jpg
    202.9 KB · Views: 7
  • termux.jpg
    termux.jpg
    397.8 KB · Views: 6
  • termux.tasker.jpg
    termux.tasker.jpg
    321.7 KB · Views: 8
  • macro.jpg
    macro.jpg
    327.9 KB · Views: 6

Endercraft

Moderator (& bug finder :D)
I prepared a simple script to verify this.
I found that the backslash was lost when passing the argument as is, so I enclosed it in double quotation marks.
I used double quotes in Termux.Tasker as well, and got the same output as Termux.
If you want to recognize newlines, use the -e option of echo.
I just realized the script couldn't attach because of file extensions.
Here it is.
 

Dimlos

Well-known member
I have improved the script a bit, but I think I am getting the results I want by running it from Termux:Tasker.
 

Attachments

  • test_txt.jpg
    test_txt.jpg
    72.3 KB · Views: 9
  • macro.jpg
    macro.jpg
    339.5 KB · Views: 10
  • result_txt.jpg
    result_txt.jpg
    74.4 KB · Views: 9
  • script.jpg
    script.jpg
    206.4 KB · Views: 8

Endercraft

Moderator (& bug finder :D)
Oh, I haven't been using Termux with variables in a long time so I completely forgot I am supposed to use %var_name and not [lv=var_name].. I'll try with that.
 
Top