Isaac
Isaac

Reputation: 11

Apple Script won't display line breaks

Making a small script to connect me to the console on some cisco equipment via a usb to serial connection in terminal.

However I am finding it impossible to put line breaks or returns in between the text and Variables (like using <br> in HTML). So in the display dialog line all the text comes out all mashed together.

I have tried using \n , \ \n, changing the preferences to Formatting > escape tabs and line Breaks in strings > Checked.

So any help would be much appreciated.

set theFind to "ls /dev/tty.*"
set theResult to do shell script theFind

set theConnection to text returned of (display dialog "Serial interface to availble:" & theResult & "Interface to use:" default answer "/dev/tty.usbserial")

tell application "Terminal"
    activate
    tell application "System Events"
        delay 1
        keystroke "screen " & theConnection & " 9600"
        keystroke return
        beep
    end tell
end tell

Upvotes: 1

Views: 628

Answers (1)

Gordon Davisson
Gordon Davisson

Reputation: 126048

AppleScript doesn't use linefeeds as line breaks (as unix generally does), it uses carriage returns. You can translate them with tr '\n' '\r' (suitably escaped, of course). Also, you'll need to manually add returns before & after the included output; for some bizarre reason, AppleScript uses \n for that instead of \r. Here's the net result:

set theFind to "ls /dev/tty.* | tr '\\n' '\\r'"
set theResult to do shell script theFind

set theConnection to text returned of (display dialog "Serial interface to availble:\n" & theResult & "\nInterface to use:" default answer "/dev/tty.usbserial")

tell application "Terminal"
    activate
    tell application "System Events"
        delay 1
        keystroke "screen " & theConnection & " 9600"
        keystroke return
        beep
    end tell
end tell

Upvotes: 1

Related Questions