AppleScript - Skype 界面

发布于 2024-11-01 15:51:24 字数 3214 浏览 3 评论 0原文

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

这是错误: 错误“变量 skype_id 未定义。”来自“skype_id”的号码 -2753

这是脚本:

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

提前感谢您的帮助。

I am very new to AppleScript. I found this script to use with a GeekTool Geeklet to show the online Skype users. When I run the AppleScript I get an error that "skype_id" is undefined. I cannot find where/why it is undefined. Apparently this same script worked in the past.

Here is the error:
error "The variable skype_id is not defined." number -2753 from "skype_id"

Here is the script:

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

Thanks in advance for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷你仙 2024-11-08 15:51:24

“my tail”是脚本自己的函数/处理程序,它只是 awk(shell)脚本的包装器。由于某种原因,该函数无法返回任何内容,并且我注意到它不包含错误检查。开始调试“on tail”块会很有用。例如,参数astring和k有意义吗?这个错误处理代码可以插入尾部处理程序的开头:

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回应的原因)。

'my tail' is the script's own function/handler, which is just a wrapper for an awk (shell) script. For some reason that function is failing to return anything, and I notice that it includes no error checking. It would be useful to start debugging the 'on tail' chunk. For example, are the parameters astring and k meaningful? This error handling code could slot into the beginning of the tail handler:

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

If that doesn't find the error, then maybe awk is misbehaving, which seems unlikely, but could still be possible I suppose.

Just a general observation. I know appleScript is suppose to be a friendly, easy going language (although it isn't), and you probably got this script from someone else, but for debugging purposes, you are asking for trouble by redefining the skype_id variable so many times. (This is the reason for Chuck's response).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文