我的最终目标是创建一个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获取前导制表位或空格的数量”并将其连接到这里?
干杯。
答案 0 :(得分:1)
Kendall Conrad在http://www.angelwatt.com/words/2011/04/11/bbedit-smart-newline-open-line/更新了类似且更具功能性的脚本。