如何将AppleScript显示对话框传递给Growl或growlnotify?


0

我有这个简单的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

谢谢。

Answers:


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

Screenshot of notification

Screenshot of application preferences


我无法弄清楚如何将我的显示对话框传递给您的脚本,所以我尝试使用文档页面中的示例脚本来完成它...但我也无法让它工作。看到: d.pr/f/xcKh
pattulus

@pattulus那是因为你不明白脚本的作用。首先,它注册一个应用程序 - 每次调用脚本时都没有损坏 - 它将作为一个单独的可配置项出现在Growl的首选项中,然后它发送一个通知,假装来自该应用程序。用适用的例子编辑我的答案......
Daniel Beck

那是对的。我不是AppleScripter,我在弄清楚语法时遇到了麻烦。非常感谢您为我提供视觉分析并提供解决方案。
pattulus

@pattulus你是受欢迎的。是时候我还是买了Growl 1.3 ......当你为它创建一个服务时,你也可以把它作为shell脚本,在命令行上使用剪贴板 pbpaste
Daniel Beck

1
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

哇。非常感谢 - 我不会想到附加引用的文本是如此容易。由于我更熟悉growlnotify的shell命令,因此对我来说这很好并且更容易掌握和实现。我给你这个Lri三个象征性的绿色复选标记。
pattulus
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.