1

制作一个小脚本,通过终端中的 USB 到串行连接将我连接到某些 cisco 设备上的控制台。

但是我发现在文本和变量之间放置换行符或返回是不可能的(比如在 HTML 中使用 <br> )。因此,在显示对话框行中,所有文本都混合在一起。

我尝试使用 \n , \ \n ,将首选项更改为格式 > 转义选项卡和字符串中的换行符 > 检查。

所以任何帮助将不胜感激。

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
4

1 回答 1

1

AppleScript 不使用换行符作为换行符(就像 unix 通常那样),它使用回车符。tr '\n' '\r'您可以使用(当然,适当地转义)来翻译它们。此外,您需要在包含的输出之前和之后手动添加返回;出于某种奇怪的原因,AppleScript 使用\n它而不是\r. 这是最终结果:

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
于 2016-01-12T06:53:08.713 回答