2009-11-09 78 views
0

本質上,我需要用AppleScript解析CHAT CREATE命令的響應字符串以獲取chatid。響應的樣子:如何使用AppleScript解析Skype響應?

CHAT#my.username/$ 123abc456blah狀態MULTICHAT

我試圖

set chatid to item 2 of response 

但回報 'H' - 我也試過

set chatid to word 2 of response 

但是,返回'我的'。我想這對於知道AppleScript的人來說是一個簡單的問題。這裏是一個示例腳本...

tell application "Skype" 
    set response to (send command "CHAT CREATE username1, username2" script name "MyScript") 
    set chatid to ***WHAT GOES HERE?*** 
    send command "ALTER CHAT " & chatid & " SETTOPIC Hello" script name "MyScript" 
end tell 

回答

3

你非常接近。試試這個:

set oldDelims to AppleScript's text item delimiters 
set AppleScript's text item delimiters to {" "} 
set chatid to text item 2 of response 
set AppleScript's text item delimiters to oldDelims 
+0

這樣做。謝謝! – 2009-11-09 22:17:07

+0

請注意* AppleScript的文本項目分隔符*技巧非常快速無法讀取。非常好地評論你的代碼 – ZJR 2009-12-16 06:41:01

0

這個人給你的ID部分(我假設是#my.username/$123abc456blah部分)

set c to "CHAT #my.username/$123abc456blah STATUS MULTICHAT" 
set hm to do shell script "perl -e '\"" & c & "\"=~/\\w (.*?) \\w/;print$1' " 

然而,這不是單純的AppleScript,我打電話perl的使用做繁重常用表達。