2013-05-17 14 views
3

我想定期彈出的通知(我有一個「當前任務」我想顯示,在番茄鍾風格的應用程序)。我試圖使用用戶啓動代理安排任務,成功地適用於運行.sh.py腳本。但是,我無法安排terminal-notifier成功啓動。其他閱讀的一個可能原因是Launch Agent進程的環境變量與通常登錄的用戶環境不同。未能從OSX中的Launch Agent運行終端通知程序(Ruby應用程序)。環境變量問題?

我安裝終端通知通過gem install terminal-notifier

[email protected]~/bin$ which terminal-notifier 
/Users/myusername/.rvm/gems/ruby-2.0.0-p0/bin/terminal-notifier 

這裏是我的shell腳本reminder.sh

#!/bin/sh 
date >>/tmp/reminder.log 
terminal-notifier -message "message txt" -title "title txt" 

直接從終端運行此腳本按預期工作:時間戳在reminder.log記錄並出現通知彈出窗口。但是,當我嘗試通過啓動代理運行它時,它會失敗。

我把~/Library/LaunchAgents/文件com.myusername.Reminder.plist有以下內容。

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>Label</key> 
    <string>com.myusername.Reminder</string> 
    <key>Program</key> 
    <string>/Users/myusername/bin/reminder.sh</string> 
    <key>RunAtLoad</key> 
    <true/> 
    <key>StartInterval</key> 
    <integer>10</integer> 
</dict> 
</plist> 

創建這個文件後,我再(如果需要的話不知道,因爲它包括RunAtLoad)加載

launchctl load ~/Library/LaunchAgents/com.myusername.Reminder.plist

launchctl start com.myusername.Reminder

雖然成功登錄一個時間戳每隔10秒到文件,它不會觸發通知。

如何使這個成功運行任何提示?

謝謝!

+0

您是否需要此問題的更多幫助? – LCC

回答

2

你的假設是正確的。 launchd(8)不知從哪裏可以找到terminal-notifier。簡單的解決方案是用絕對路徑調用terminal-notifier。調整你的shell腳本是這樣的:

#!/bin/sh 
date >>/tmp/reminder.log 
/Users/myusername/.rvm/gems/ruby-2.0.0-p0/bin/terminal-notifier -message "message txt" -title "title txt" 

另外,您可以使用launchd會一直延長PATH環境變量(8)鍵EnvironmentVariables。作業定義中的相應部分應如下所示:

<key>EnvironmentVariables</key> 
<dict> 
    <key>PATH</key> 
    <string>/usr/bin:/bin:/usr/sbin:/sbin:/Users/myusername/.rvm/gems/ruby-2.0.0-p0/bin</string> 
</dict> 
相關問題