AppleScript 字数统计服务
我正在尝试在 OSX Leopard 中创建一项服务来计算所选文本的字数。我将自动化程序设置为运行一个 applescript,其中包含以下内容:
on run {input, parameters}
count words of input
display alert "Words: " & input
return input
end run
当我编译脚本时,它说它无法计算每个单词。我做错了什么?
感谢您的帮助,
埃利奥特
I am trying to create a service in OSX leopard that counts the number of words of selected text. I have automator set to run an applescript, with the following put in it:
on run {input, parameters}
count words of input
display alert "Words: " & input
return input
end run
When I compile the script, it says it cannot count every word. What am I doing wrong?
Thanks for the help,
Elliott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我假设您正在 Automator 中对此进行测试,这就是发生错误的地方?如果是这样,可能的问题是没有输入,因此它无法计算空的单词数。为了成功测试它,您需要在“运行AppleScript”操作之前临时添加“获取指定文本”操作,并在该字段中输入一些测试文本。在将其用作实际服务之前,您必须删除“获取指定文本”操作。
其次,您需要使用
以获得正确的计数,否则它将返回零。
First of all, I presume you are testing this in Automator, and that's where the error is taking place? If so, the likely problem is that there is no input—so it can't count the words of nothing. In order to test it successfully, you need to temporarily add a "Get Specified Text" action before the Run AppleScript action, and enter some test text into that field. You'll have to remove the Get Specified Text action before using it as an actual service.
Secondly, you need to use
in order to get a proper count, otherwise it'll return zero.
我在 Github 上做了一个:
https://gist.github.com/1616556
当前来源是:
使用 Automator.app 创建新服务,然后选择“运行 AppleScript”操作。将此代码粘贴到文本框中,然后另存为“字数和字符数”。现在切换到新应用程序,选择一些文本,然后打开上下文菜单以查找新选项。
I made one here, on Github:
https://gist.github.com/1616556
The current source is:
Use Automator.app to create a new service, and then select the Run AppleScript action. Paste this code in to the text box, and save as Word and Character Count. Now switch to a new app, select some text, and open the context menu to find the new option.