我正在使用nslater 的精彩脚本来计算选定文本块中的单词和字符,但我需要两个增强功能:
即使没有选择文本,也可以使用脚本。目前,当我在没有选择的情况下拉出可用服务列表时,服务不存在(当然,这是合乎逻辑的,但增强 #2 会改变事情)。
向脚本添加条件行为:如果未选择文本,则处理所有文本,但如果有选择,则仅处理所选文本。
这是nslater 的脚本,我将其粘贴到 Automator 中(我按照他注释说明中的步骤创建了服务):
# Word and Character Count service for Mac OS X
#
# Adds a Word and Character Count option to the text selection context menu in all apps
#
# 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.
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