AppleScript的字数服务
-
21-09-2019 - |
题
我想在OSX豹创建服务才是最重要的选择文本的单词的数量。我有自动机设置为运行AppleScript,具有以下放于它:
on run {input, parameters}
count words of input
display alert "Words: " & input
return input
end run
当我编译脚本,它说,它不能指望每一个字。我在做什么错了?
感谢您的帮助,
埃利奥特
解决方案
首先,我想你在Automator的测试这一点,这就是错误的发生?如果是这样,可能的问题是,有没有输入,因此不能算什么话。为了成功地测试它,你需要在运行AppleScript动作之前临时添加一个“获取指定的文本”动作,并输入一些测试文本到该字段。你必须把它作为一个实际的服务之前删除获取指定的文本采取行动。
其次,你需要使用
count words of (input as string)
为了得到合适的数量,否则它会返回零。
其他提示
我由一种在这里,在Github:
https://gist.github.com/1616556
电流源是:
on run {input, parameters}
tell application "System Events"
set _appname to name of first process whose frontmost is true
end tell
set word_count to count words of (input as string)
set character_count to count characters of (input as string)
tell application _appname
display alert "" & word_count & " words, " & character_count & " characters"
end tell
return input
end run
使用Automator.app创建一个新的服务,然后选择运行AppleScript动作。在文本框这个代码粘贴,并保存为Word和字符计数。现在切换到新的应用程序,选择一些文本,并打开上下文菜单中找到新的选项。
不隶属于 StackOverflow