How to parse Skype response with AppleScript?
Essentially, I need to parse the response string of the CHAT CREATE command with AppleScript to get the chatid. The response looks like:
CHAT #my.username/$123abc456blah STATUS MULTIC开发者_Python百科HAT
I tried
set chatid to item 2 of response
but that returns 'H' -- I also tried
set chatid to word 2 of response
but that returns 'my'. I imagine this is an easy question for someone that knows AppleScript. Here is a sample script...
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
You're very close. Try this:
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
This one gives you the ID part (which I assume is the #my.username/$123abc456blah
part)
set c to "CHAT #my.username/$123abc456blah STATUS MULTICHAT"
set hm to do shell script "perl -e '\"" & c & "\"=~/\\w (.*?) \\w/;print$1' "
However this isn't pure AppleScript, I call perl to do the heavy lifting using regular expressions.
精彩评论