获取制表位或空白的数量,并在Applescript(插入项目符号的智能换行脚本)中连接

获取制表位或空白的数量,并在Applescript(插入项目符号的智能换行脚本)中连接,applescript,bbedit,Applescript,Bbedit,我的最终目标是创建一个applescript,当我按下Alt+Enter键时,它可以智能地为我自动插入一个项目符号。我正试图在BBEdit中实现这一点,以下是我从BBEdit论坛上获取的苹果脚本: tell application "BBEdit" try tell text of front text window set lineOfInsertionPoint to line (startLine of selection)

我的最终目标是创建一个applescript,当我按下Alt+Enter键时,它可以智能地为我自动插入一个项目符号。我正试图在BBEdit中实现这一点,以下是我从BBEdit论坛上获取的苹果脚本:

tell application "BBEdit"
    try
        tell text of front text window
            set lineOfInsertionPoint to line (startLine of selection)
            set findReco to find "^\\s*\\d+\\." searching in lineOfInsertionPoint options {search mode:grep}
            if found of findReco = true then
                set leadingNumber to text 1 thru -2 of (found text of findReco)
                set text of selection to return & (leadingNumber + 1) & ". "
                select insertion point after selection
            else if found of findReco = false then
                set findReco to find "^\\s*\\* " searching in lineOfInsertionPoint options {search mode:grep}
                if found of findReco = true then
                    set text of selection to return & "* "
                    select insertion point after selection
                else
                    set findReco to find "^\\s*\\+" searching in lineOfInsertionPoint options {search mode:grep}
                    if found of findReco = true then

                        set text of selection to return & tab & "+ "
                        select insertion point after selection
                    end if
                end if
            end if
        end tell
    on error errMsg number errNum
        set sep to "=============================="
        set e to sep & return & "Error: " & errMsg & return & sep & return ¬
            & "Error Number: " & errNum & return & sep
        beep
        display dialog e
    end try
end tell
该脚本运行良好,但问题是,当您在开始处已经有一定数量的制表位或空白时,applescript将在行首插入下一个项目符号,忽略空白/制表位

因此,我的实际问题很简单,“如何通过Applescript获得前导制表位或空白的数量”,并将其连接到这里


干杯。

肯德尔·康拉德(Kendall Conrad)在上更新了一个类似的、功能更强大的脚本