2012-05-30 49 views
0

我很想從命令行發送我的Adium聯繫人消息。語法應該看起來像echo test | im <contact>。我已經採取並修改了this script來做我想做的事情,但它有點老,我正在嘗試對其進行現代化。到目前爲止,我已經得到了這個工作(我只是改變了AppleScript的,在這裏。)Adium從蘋果發送兩條聊天消息

set stdinText to do shell script "echo \"\$MESSAGE\"" without altering line endings 

tell application "Adium" 
    set user to get contact "$BUDDY" 

    if not (exists (chats whose contacts contains user)) then 
     if not (exists (first chat window)) then 
      tell account of user 
       set new_chat to make new chat with contacts {user} with new chat window 
      end tell 
     else 
      set existing_window to first chat window 
      tell account of user 
       set new_chat to make new chat with contacts {user} in window existing_window 
      end tell 
     end if 
    else 
     set new_chat to first chat whose contacts contains user 
    end if 

    send new_chat message stdinText 
end tell 

效果很好,除了聊天消息發送兩次。這是Adium中的一個錯誤還是我在AppleScript中做錯了?

+0

從[Adium的AppleScript文檔](http://trac.adium.im/wiki/AppleScript_Support_1.2)判斷,您的腳本可能可以簡化,但我看不到任何可能導致雙重發送的內容。 OTOH,[沒有Adium漏洞聽起來像你的問題那樣的票](http://trac.adium.im/query?status=assigned&status=new&status=pending&description=%7EApplescript&group=type&col=id&col=summary&col=status&col=所有者COL =類型&COL =里程碑&順序=優先級)。我想知道在您的特定配置中是否有問題導致問題(可能會創建雙重聊天會話)? – kopischke

回答

1

我也遇到了這個bug,Adium多次發送聊天消息。

這是由名爲AdiumApplescriptRunner的多個正在運行的後臺進程引起的。顯然只有其中一個進程應該在任何給定的時間運行,但有時會啓動多個進程,當發生這種情況時,會爲每個額外的AdiumApplescriptRunner進程發送重複的聊天消息。

我的解決辦法是建立一個cron任務,運行每分鐘,並執行該bash命令:

ps -aef | grep -v grep | grep 'AdiumApplescriptRunner' | awk '{print $2}' | awk 'NR == 2,/c/' | xargs -I %s kill -9 %s 

此命令可以確保只有一個名爲AdiumApplescriptRunner一個進程正在運行,並殺死任何但是一Adium創建的。

相關問題