2011-04-14 75 views
0

我對AppleScript很新穎。我發現這個腳本可以與GeekTool Geeklet一起使用,以顯示在線Skype用戶。當我運行AppleScript時,出現「skype_id」未定義的錯誤。我找不到未定義的位置/原因。顯然這個同樣的腳本在過去工作。AppleScript - Skype界面

這是錯誤: 錯誤「變量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 

在此先感謝您的幫助。

+0

這將有助於知道錯誤發生在哪一行。 – Chuck 2011-04-15 05:30:46

+0

它發生在這裏: – Scott 2011-04-18 06:45:17

+0

將skype_id設置爲我的尾巴(skype_id,4) – Scott 2011-04-18 06:46:15

回答

0

'我的尾巴'是腳本自己的函數/處理函數,它只是awk(shell)腳本的包裝。出於某種原因,該函數無法返回任何內容,並且我注意到它沒有包含錯誤檢查。開始調試'尾部'塊將會很有用。例如,參數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變量多次要求麻煩。 (這是查克迴應的原因)。