1

我正在尝试修改 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,所以我不知道如何将“带字符串的字符串”转换为驼峰式,即stringWithString。

如果我能学会这个基本的东西,我也许最终可以开始通过语音编程,这比处理流行的小键盘和游戏键盘更好,但我发现它们很糟糕。

4

1 回答 1

2

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

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"是正确的,因此您只需将任何所需的字母与其大写的等效字母进行比较,然后替换它。

我希望这有帮助。

于 2015-06-29T00:11:39.083 回答