如何在 AppleScript 中将一系列单词转换为驼峰式大小写?

How can I convert a series of words into camel case in AppleScript?

我正在尝试修改 Dragon Dictate,它可以用已经说出的一系列单词执行 AppleScript。我需要找出如何获取包含这些单词的字符串并将其转换为驼峰式大小写。

on srhandler(vars)
    set dictatedText to varDiddly of vars
    say dictatedText
end srhandler

因此,如果我设置一个宏来执行上述脚本,称为 camel,并且我说 "camel string with string",dictedText 将设置为 "string with string"。这是DD的一个很酷的功能。但是我不知道 AppleScript,所以我不知道如何将 "string with string" 转换为驼峰式大小写,即 stringWithString.

如果我能学会这个基本的东西,我也许 最终 开始通过语音编程,这比处理 chicklet 键盘和玩家键盘要好,后者很流行,但我发现他们太糟糕了。

如果您只需要将短语转换为驼峰文本,我会这样做:

set targetString to "string with string"
set allCaps to every character of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
global allCaps
set camel to my MakeTheCamel(targetString)

to MakeTheCamel(txt)
    set allWords to every word of txt
    set camelString to ""
    repeat with eachWord in allWords
        set char01 to character 1 of (eachWord as text)
        set remainder to characters 2 thru -1 of (eachWord as text)
        repeat with eachChar in allCaps
            if char01 = (eachChar as text) then
                set camelString to camelString & (eachChar as text) & (remainder as text)
                exit repeat
            end if
        end repeat
    end repeat
    return camelString
end MakeTheCamel

由于 AppleScript 认为 "a" = "A" 为真,您只需将任何需要的字母与其大写字母进行比较,然后替换它。

希望对您有所帮助。