AppleScript-Skype接口

AppleScript-Skype接口,applescript,skype,Applescript,Skype,我对AppleScript很陌生。我发现这个脚本与GeekTool Geeklet一起使用,用于显示在线Skype用户。当我运行AppleScript时,我得到一个错误,“skype_id”未定义。我找不到未定义的位置/原因。显然,同样的剧本在过去也起作用 错误如下: 错误“变量skype_id未定义”。数字-2753来自“skype_id” 以下是脚本: on remvix(ix, ls) if ls is {} then return {} else if ix is 1 then

我对AppleScript很陌生。我发现这个脚本与GeekTool Geeklet一起使用,用于显示在线Skype用户。当我运行AppleScript时,我得到一个错误,“skype_id”未定义。我找不到未定义的位置/原因。显然,同样的剧本在过去也起作用

错误如下: 错误“变量skype_id未定义”。数字-2753来自“skype_id”

以下是脚本:

on remvix(ix, ls)
if ls is {} then
    return {}
else if ix is 1 then
    return rest of ls
else
    return {item 1 of ls} & remvix(ix - 1, rest of ls)
end if
end remvix

on tail(astring, k)
return do shell script "echo '" & astring & "' | awk '{{i = " & k & "; while ( i <= NF-1 ) {printf $i \" \"; i++}; printf $i}}'"
end tail

property onlinegroup : 0

on getgroup()
tell application "Skype"
    if my checkgroup(onlinegroup) is true then
        return onlinegroup
    else
        set hardwired to send command "search groups hardwired" script name "online users"
        set hardwired to my tail(hardwired, 2)
        set hardwired to text items of hardwired
        repeat with i in hardwired
            if my checkgroup(i) is true then
                return i
            end if
        end repeat
    end if
end tell
end getgroup

on checkgroup(group_id)
tell application "Skype"
    set grouptype to send command "get group " & group_id & " type" script name "online users"
    set grouptype to my tail(grouptype, 4)
    if grouptype is "ONLINE_FRIENDS" then
        return true
    else
        return false
    end if
end tell
end checkgroup

property dropped : 0
set text item delimiters to ", "
set onlineusers to {}
tell application "System Events"
set powerCheck to ((application processes whose (name is equal to "Skype")) count)

if powerCheck = 0 then
    set end of onlineusers to " Skype not running"
else
    tell application "Skype"
        set onlinegroup to my getgroup()
        set skype_id to send command "get group " & onlinegroup & " users"    script name "online users"
        set skype_id to my tail(skype_id, 4)
        set skype_id to text items of skype_id
        repeat with j from 1 to count skype_id
            if item j of skype_id is "echo123" then
                set skype_id_new to my remvix(j, skype_id)
                set dropped to 1
            end if
        end repeat
        if dropped is 1 then
            set skype_id to skype_id_new
        end if
        repeat with i in skype_id
            set aUser to send command "get user " & i & " fullname" script name "online users"
            set aUser to my tail(aUser, 4)
            if aUser is "" then set aUser to i
            set amoodtext to send command "get user " & i & " mood_text" script name "online users"
            set amoodtext to my tail(amoodtext, 4)
            if amoodtext is "" then
                set end of onlineusers to aUser
            else
                set end of onlineusers to aUser & " (" & amoodtext & ")"
            end if
        end repeat

        if (count skype_id) > 0 then
            set item 1 of onlineusers to " " & item 1 of onlineusers
        else
            set beginning of onlineusers to " No Contacts Online"
        end if
        return onlineusers
    end tell
end if
end tell
remvix(ix,ls)上的

如果ls是{},那么
返回{}
否则,如果ix为1,则
返回剩余的ls
其他的
返回{ls项目1}&remvix(ix-1,ls其余部分)
如果结束
雷姆维克斯终点
在尾部(收敛,k)

return do shell脚本“echo”&astring&“|awk”{{{i=“&k&”,而(i“my tail”是脚本自己的函数/处理程序,它只是awk(shell)的包装器脚本。由于某些原因,该函数无法返回任何内容,并且我注意到它没有包含错误检查。开始调试“on tail”块会很有用。例如,参数astring和k是否有意义?此错误处理代码可能插入tail处理程序的开头:

if ((class of astring) is not string) or ((class of k) is not integer) then
display dialog "Screwy parameter sent to tail" buttons {"Rats"} default button 1
error number -128 -- abort script entirely 
end if
如果这没有发现错误,那么可能是awk行为不端,这似乎不太可能,但我认为仍然有可能


这只是一个一般性的观察。我知道appleScript被认为是一种友好、易用的语言(尽管它不是),你可能从其他人那里得到了这个脚本,但是为了调试的目的,你多次重新定义skype_id变量是在自找麻烦。(这就是Chuck回答的原因).

知道错误发生在哪一行会很有帮助。将skype\u id设置为my tail(skype\u id,4)