Thursday, December 14, 2017

#1 2016-10-14 04:02:40 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

\n my best friend...

Hey guys

A while a go I wrote an applescript that did a lot of useful operations for me.

A part of it was to create a string that contained some "\n" like  for QR CODE generation in InDesign.

Applescript:


Somestring\nSomeotherString\nThirdString

As you cannot write \n in applescript - it causes libebreaks inside the script,-I used some characters instead of the ,\n' s like "#$%" and had a bash script replace them with "\n". Now I was wondering if there's a better method with object c to get a string that contains multiple "\n"

Offline

 

#2 2016-10-14 05:30:43 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: \n my best friend...

You can use:

Applescript:

"Somestring" & linefeed &"SomeotherString" & linefeed &"ThirdString"


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2016-10-14 05:49:31 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: \n my best friend...

I tried that before. It doesn't work for my purpose. It has to be "\n" as text and line feed doesn't print that it just makes a newline.

Offline

 

#4 2016-10-14 05:55:25 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: \n my best friend...

If you want to print \n you use \\n.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2016-10-14 06:04:46 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: \n my best friend...

And this is where the problems start smile
I tried that also.

I need to write a line like this in a file with a batch command (not the AS 'write to file')

"String\nOtherString\nThirdString"

If I escape \\n it writes exactly that to file...

"String\\nOtherString\\nThirdString"

Which is wrong...

My thoughts were more like having an NSARRAY  {String,Other string,..} an join it somehow with \n as separator

Offline

 

#6 2016-10-14 06:26:58 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: \n my best friend...

Can you show us your code/

It sounds like you should be using what I suggested originally, but quoting it.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#7 2016-10-17 05:48:27 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: \n my best friend...

Erm... it works with the escape. Dunno why it didn't when I tried first. Close! hmm

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)