2012-09-23 36 views
1

抱歉編寫Applescript的新功能,以便獲得任何幫助。嘗試在telnet腳本之間插入文本之間的引號

我試圖創建一個腳本,將剪貼板中的文本粘貼到telnet命令的中間。輸出需要在同一個窗口,並期待有點像這樣:

I8,A,001 
Q102,024 
q448 
rN 
S4 
D15 
ZT 
JF 
O 
R71,0 
f100 
N 
B264,65,2,UA0,2,4,56,B,"100000000045" 
A203,82,2,1,2,2,N,"xxxxx" 
P1 

引述的12位數字,在第13行是我需要插入。

這是我到目前爲止編碼,但它不工作:一旦

tell application "Terminal" 

    do script "telnet xxx.xxx.xx.xx xxxx" 
    delay 1 
    do script "I8,A,001" in window 1 
    do script "Q102,024" in window 1 
    do script "q448" in window 1 
    do script "rN" in window 1 
    do script "S4" in window 1 
    do script "D15" in window 1 
    do script "ZT" in window 1 
    do script "JF" in window 1 
    do script "O" in window 1 
    do script "R71,0" in window 1 
    do script "f100" in window 1 
    do script "N" in window 1 
    do script "B264,65,2,UA0,2,4,56,B,\"" 
    tell application "System Events" 
     tell application process "Terminal" in window 1 
      keystroke "v" using {command down} 
     end tell 
     keystroke "\"" 
     keystroke return 
     do script "\"A203,82,2,1,2,2,N,\"xxxxx\"" 
     do script "P1" 
     keystroke return 
    end tell 
end tell 

,我嘗試使用命令V粘貼到退出終端窗口和粘貼什麼上的腳本剪貼板相反,它不會讓我告訴它留在終端窗口1中。

+0

有沒有一種方法來編寫一個獨特的11位數字,然後爲UPC-A做一個校驗和,然後在引號內使用它而不是使用Command V?現在我正在使用Excel創建序列號和添加校驗和的公式。 – cav719

回答

0

您不需要使用command-v將剪貼板內容存入終端窗口。 Applescript可以獲得剪貼板,然後在「執行腳本」之前將其添加到字符串的其他部分。像這樣的工作......當然你不需要代碼的第一行,因爲剪貼板應該已經有了這個值。

set the clipboard to "100000000045" 

set t1 to "B264,65,2,UA0,2,4,56,B,\"" 
set t2 to the clipboard 
set t to t1 & t2 & "\"" 
do script t in window 1 
+0

謝謝,但剪貼板部分不會總是相同的12位數字。這將是一個獨特的12位數字每次。 – cav719

+0

12位數字將是一個11位數字加上唯一或連續的UPC-A條形碼的校驗和。 – cav719

+0

沒關係。正如我所提到的,將第一行代碼留出。我只把它放在那裏,所以我可以測試腳本。無論剪貼板上的任何內容都會進入字符串,所以沒有問題。只需用代碼中的第2到第5行替換最後的「腳本」行和整個「告訴應用程序系統事件」部分的代碼,它應該可以工作。 – regulus6633

0

這是我最後用得到它,以防其他人的工作需要它:

tell application "Terminal"

do script "telnet xxx.xxx.xx.xx xxxx" 
delay 1 
do script "I8,A,001" in window 1 
do script "Q102,024" in window 1 
do script "q448" in window 1 
do script "rN" in window 1 
do script "S4" in window 1 
do script "D15" in window 1 
do script "ZT" in window 1 
do script "JF" in window 1 
do script "O" in window 1 
do script "R71,0" in window 1 
do script "f100" in window 1 
do script "N" in window 1 
set t1 to "B264,65,2,UA0,2,4,56,B,\"" 
set t2 to the clipboard 
set t to t1 & t2 & "\"" 
do script t in window 1 
do script "A203,82,2,1,2,2,N,\"xxxxx\"" in window 1 
do script "P1" in window 1 

end tell

感謝您的幫助軒轅!