如何將AppleScripts顯示對話框傳遞給Growl或growlnotify?

如何將AppleScripts顯示對話框傳遞給Growl或growlnotify?

我有一個簡單的 AppleScript,它獲取剪貼簿中的文字並輸出所使用的單字和字元的數量。

我想做的是將“顯示對話框”傳遞給 Growl 或 Growlnotify。我知道如何在 shell 中使用 Growlnotify - 它很棒且高度可自訂(貼上註釋、分配應用程式圖標或圖像等) - 但重點是:我不知道如何在 AppleScript 中執行此操作。我用谷歌搜尋了一下,但現在時間已經過去了,我決定在這裡發布我的問題。

所以,這是腳本:

set myCount to count (the clipboard)
set myWords to count words of (the clipboard)
set myParas to count paragraphs of (the clipboard)

display dialog "Characters: " & myCount & "
Words: " & myWords & "
Paragraphs: " & myParas

謝謝。

答案1

文件為此,我提供了一個例子在這個答案中

以下適用於 OS X Lion 上的 Growl 1.3.3:

tell application "Growl"
    set the allNotificationsList to {"Word Count"}
    set the enabledNotificationsList to {"Word Count"}

    register as application "Word Counter" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Script Editor"

    set myCount to count (the clipboard)
    set myWords to count words of (the clipboard)
    set myParas to count paragraphs of (the clipboard)
    --       Send a Notification...
    notify with name "Word Count" title "Word Counter" description (myCount as text) & " " & (myWords as text) & " " & (myParas as text) application name "Word Counter"
end tell

通知截圖

應用程式首選項的螢幕截圖

答案2

set input to the clipboard as text
set output to (number of characters of input & " characters
" & number of words of input & " words
" & number of paragraphs of input & " paragraphs") as text
do shell script "/usr/local/bin/growlnotify " & quoted form of output
-- brew install growlnotify

相關內容