如何使用AppleScript解析Skype响应?

时间:2009-11-09 11:38:40

标签: string applescript skype

基本上,我需要使用AppleScript解析CHAT CREATE命令的响应字符串以获取chatid。回复如下:

  

CHAT#my.username / $ 123abc456blah STATUS 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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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使用正则表达式进行繁重的工作。