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 に答える