在OS X中建立一个字数统计服务

虽然一些文字处理应用自己带有字数统计功能,但是本文的方法可以建立一个通用的字数统计服务,包括浏览器都可以使用。

1、使用Automator建立字数统计服务

a、打开Automator,选择建立“Service”;

b、在左上角搜索框输入“run applescript”,然后将搜索结果拖到右方面板中;

c、将以下代码(原代码在https://gist.github.com/nslater/1616556/raw/316da039e6f87a4f6c3dfddc4b84684c942254b7/Word+and+Character+Count.scpt)复制粘贴到“run applescript”面板代码区;

# 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

d、保存,可以命名为“Count Characters & Words”。

2、使用字数统计服务

打开TextEdit,输入一些文字,全选或是选中需要计数的文字,右键,在菜单“Services”中选择“Count Characters & Words”,弹出框即会显示字数统计。

3、取消右键中的服务

在系统的“System Preferences”中选择“Keyboard”-“Shortcuts”-“Services”,找到“Count Characters & Words”,取消前面的勾选,右键菜单就不会出现选项了。

原文:http://osxdaily.com/2014/01/27/word-character-counter-service-mac-os-x/

【 阅读次数:1266 】