Script Cue - echo with carriage return

1,044 views
Skip to first unread message

Lasse Bohnsack

unread,
Oct 27, 2019, 7:28:28 AM10/27/19
to QLab
Hey,
I'm trying to do a script Cue as follows:
"Do shell script "echo 'value CR' "

This script Cue is supposed to echo a message out via Ncat / Netcat. The echo string needs to contain a carriage return. Unfortunately, "^M" does not work. When I try to use \n or \r the script itself produces a line break.

Is there any way, to echo a carriage return?

Best

Lasse

Michael Heath

unread,
Oct 27, 2019, 3:17:00 PM10/27/19
to ql...@googlegroups.com
Hi Lasse -

I'd have to see the full context of what you're trying to do to give you exact advice, but here's a few tips:

In shell scripting, Single Quotes (that is, the ' character) means the shell does no interpretation of the text. On it's own, '\n' is literally the text \n . 

Double quotes (that is, the " character) mean the shell interprets the character. "\n" gets replaced by the shell by the actual ASCII newline character.

The other way you can handle this is by giving echo the "-e" option. That causes the echo command itself to interpret \n. 

So there's two ways:

echo "\n"   <-- Shell interprets \n by replacing it with the newline character, and then sends that to echo, which echoes it
echo -e '\n'  <-- Shell does nothing with the literal string '\n' but send it to echo. echo, though, interprets it as the newline character and echoes that.

Hope this helps.

--
Contact support anytime: sup...@figure53.com
Follow Figure 53 on Twitter: https://twitter.com/Figure53
User Group Code of Conduct: https://figure53.com/help/code-of-conduct/
---
You received this message because you are subscribed to the Google Groups "QLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qlab+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qlab/5d4b4f19-4038-4421-b39f-2d37b26fb6f5%40googlegroups.com.

Lasse Bohnsack

unread,
Oct 27, 2019, 7:11:30 PM10/27/19
to QLab
Hey Michael,

thank you for your quick and elaborate response.
Echo sending out the Carriage Return is not the problem - when I'm using the terminal it works just fine like this:

Bildschirmfoto 2019-10-28 um 00.02.46.png





When i try to call this with an applescript Cue in Qlab, it does not work the way it should - instead of a carriage return, the literal "^M" is being sent.

Bildschirmfoto 2019-10-28 um 00.01.42.png

When i try to replace the "^M" with \n or \r, Qlab inserts a line break in the script, once compiled.

Bildschirmfoto 2019-10-28 um 00.03.13.png
Bildschirmfoto 2019-10-28 um 00.03.25.png







I know i could probably call the terminal to perform the commands. Still, i would prefer Qlab to perform these actions - it's just quicker than opening the terminal.


Thank you for your support!

Lasse

Michael Heath

unread,
Oct 27, 2019, 8:26:01 PM10/27/19
to ql...@googlegroups.com
Try this (apologies for any errors, I'm not in front of a Mac at the moment to actually run, so this may need some validation or minor debugging):

set messageText to "test" & linefeed
set ncatCommand to "ncat IP PORT"
do shell script "echo -n " & quoted form of messageText & " | " & ncatCommand
 

A bit of explanation: the behavior you're seeing where the applescript compiler is replacing your \n with an actual visible linefeed is normal and intentional. The standalone applescript editor in MacOS actually has an option in preferences to disable this behavior, but I don't think the qlab script cue editor exposes this option. Strictly speaking it should actually still work as intended; applescript handles breaks in the middle of a string deceleration as actual breaks in the text. But it's a bit weird, especially for people used to string handling in pretty much any other programming language. 

Here's some advanced reading on the ins-and-outs of text and special character escaping in Applescript:

 

Michael Heath

unread,
Oct 28, 2019, 3:32:48 PM10/28/19
to ql...@googlegroups.com
Just tested. Just drop off the -n echo argument.... I can’t find any docs to explain it, but -n isn’t treated as a command line argument when sent this way. It seems to already be implied when calling echo this way, though, so it isn’t needed. 

On Sun, Oct 27, 2019 at 5:25 PM Michael Heath <mic...@shoreline.church> wrote:
Try this (apologies for any errors, I'm not in front of a Mac at the moment to actually run, so this may need some validation or minor debugging):

set messageText to "test" & linefeed
set ncatCommand to "ncat IP PORT"
do shell script "echo -n " & quoted form of messageText & " | " & ncatCommand
--

Michael Heath

Production Coordinator / IT Director

Shoreline.Church

831.655.0100 x 340

mic...@shoreline.church


Rich Walsh

unread,
Nov 23, 2019, 6:07:22 PM11/23/19
to ql...@googlegroups.com
Sorry, it's taken me ages to get to this. This behaviour is because AppleScript's shell is sh not bash (which is what Terminal uses). The man page for echo says "Most notably, the builtin echo in sh(1) does not accept the -n option.".

There are lots of exciting quirks you run into thinking that something in Terminal will work in AS – process substitution isn't supported in sh for example…

In terms of the original question, to stop the AS editor parsing \n to a linefeed upon compiling, you have to escape out the escape character, ie:

do shell script "echo 'test\\n'"

Again, this gets really confusing really fast!

Rich

Lasse Bohnsack

unread,
Dec 12, 2019, 12:19:54 PM12/12/19
to ql...@googlegroups.com
Nice, thank you! it worked just fine!

Lasse

--
Contact support anytime: sup...@figure53.com
Follow QLab on Twitter: https://twitter.com/QLabApp
User Group Code of Conduct: https://qlab.app/code-of-conduct/

---
You received this message because you are subscribed to the Google Groups "QLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qlab+uns...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages