Sending line breaks in SMS over dbus-send?

I sometimes send texts over terminal with

dbus-send --system --print-reply --dest=org. ofono /ril_0 org.ofono.MessageManager.SendMessage string:"number" string:"Hej"

I can paste in any emojis, but line-breaks break the command.

I tried \n and a few other ways to add line breaks, but can’t get it to work. Any ideas?

Also, this is on an XA 2 with the username nemo, I don’t think it can be run with the new user system.

Works for me, at least when entering “live”, i.e. on cli prompt before the last quote character.

dbus-send --system --print-reply --dest=org. ofono /ril_0 org.ofono.MessageManager.SendMessage string:"number" string:"Hello
my
friend
"

Ah, I am SSHing in to the phone… I guess that is the issue.

I wrote myself a script to compose a message on my computer, then send it to the SMS app on my phone (also good for just sending arbitrary strings to the phone).

It does NOT send messages, just transfers the text.

Anyhow, I had similar problems at first and ended up with this, which works reliably:

#!/bin/bash

host=xa2 # defined in ~/.ssh/config

sep="=================="
printf "Enter message text\n$sep\n"
# Read stdin & escape it https://stackoverflow.com/a/20053121
text="$(LC_ALL=C sed -e 's/[^a-zA-Z0-9,._+@%/-]/\\&/g; 1{$s/^$/""/}; 1!s/^/"/; $!s/$/"/' /dev/stdin)"
exec ssh $host DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/100000/dbus/user_bus_socket dbus-send --type=method_call --dest=org.nemomobile.qmlmessages / org.nemomobile.qmlmessages.startSMS array:string:\"\" string:$text