0

我的最终目标是创建一个applescript,当我点击 Alt + Enter 时,它会智能地自动为我插入一个项目符号点。我正在尝试在 BBEdit 中执行此操作,这是我从 BBEdit 论坛中获取的 Apple 脚本:

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获取前导制表位或空格的数量”并将其连接在这里?

干杯。

4

1 回答 1

1

Kendall Conrad 在http://www.angelwatt.com/words/2011/04/11/bbedit-smart-newline-open-line/上更新了一个类似且功能更强大的脚本。

于 2012-03-30T10:53:27.377 回答