views:

156

answers:

2

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 MULTICHAT

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
+3  A: 

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
Gene Goykhman
That did the trick. Thanks!
g .
Be aware that *AppleScript's text item delimiters* tricks become unreadable really fast. Comment your code very well
ZJR
A: 

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.

adamse