如何将 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

相关内容