【问题标题】:AppleScript Word Count ServiceAppleScript 字数统计服务
【发布时间】:2010-11-26 03:20:22
【问题描述】:

我正在尝试在 OSX leopard 中创建一个服务来计算所选文本的字数。我已将自动机设置为运行一个 applescript,其中包含以下内容:

on run {input, parameters}
        count words of input
        display alert "Words: " & input
        return input
end run

当我编译脚本时,它说它不能计算每个单词。我做错了什么?

感谢您的帮助,

艾略特

【问题讨论】:

    标签: applescript osx-snow-leopard counting word-count


    【解决方案1】:

    首先,我假设您正在 Automator 中对此进行测试,而这就是发生错误的地方?如果是这样,可能的问题是没有输入——所以它不能数空话。为了成功测试它,您需要在 Run AppleScript 操作之前临时添加一个“获取指定文本”操作,并在该字段中输入一些测试文本。在将其用作实际服务之前,您必须删除 Get Specified Text 操作。

    其次,你需要使用

    count words of (input as string)
    

    为了得到正确的计数,否则它将返回零。

    【讨论】:

    • 感谢您的回答-我遇到了不使用字符串的问题,所以感谢您清除它。
    【解决方案2】:

    我在这里做了一个,在 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 操作。将此代码粘贴到文本框中,并另存为字数和字符数。现在切换到一个新应用,选择一些文本,然后打开上下文菜单以找到新选项。

    【讨论】:

      猜你喜欢
      • 2010-09-16
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-21
      相关资源
      最近更新 更多