use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
tell application "CotEditor"
if exists front document then
tell front document
-- get selection's positional data
set {locLength, selectionLength} to range of selection
set {locLines, selectionLines} to line range of selection
set looseSelect to 0
-- whole lines select
if (selectionLines is greater than or equal to looseSelect as number) then
set line range of selection to {locLines, selectionLines}
set {locLength, selectionLength} to range of selection
end if
-- ignore last line break
if contents of selection ends with "
" then set range of selection to {locLength, selectionLength - 1}
set theSelection to contents of selection
end tell
end if
end tell
set regex to "^(/.+):([0-9]+):(.*)"
set aRes to re_match from theSelection against regex given replacement:"/usr/local/bin/cot $1 -l $2"
if aRes is not equal to {} then
delay 0.2
do shell script aRes
end if
on re_match against pattern from str given replacement:fmt
set regex to current application's NSRegularExpression's ¬
regularExpressionWithPattern:pattern ¬
options:(current application's ¬
NSRegularExpressionCaseInsensitive) ¬
|error|:(missing value)
(regex's stringByReplacingMatchesInString:str ¬
options:0 range:{0, length of str} ¬
withTemplate:fmt) ¬
as text
end re_match
tell application "CotEditor"
if exists front document then
tell front document
if coloring style is not in {"Markdown"} then
quit
end if
-- get selection's positional data
set {locLength, selectionLength} to range of selection
set {locLines, selectionLines} to line range of selection
set looseSelect to 0
-- whole lines select
if (selectionLines is greater than or equal to looseSelect as number) then
set line range of selection to {locLines, selectionLines}
set {locLength, selectionLength} to range of selection
end if
-- ignore last line break
if contents of selection ends with "
" then set range of selection to {locLength, selectionLength - 1}
-- get contents
set theSelection to contents of selection
if rich text 1 of theSelection is equal to "#" then
set contents of selection to "#" & theSelection
end if
end tell
end if
end tell
見出しレベルを上げる(md_heading_up.^@j.applescript)
tell application "CotEditor"
if exists front document then
tell front document
if coloring style is not in {"Markdown"} then
quit
end if
-- get selection's positional data
set {locLength, selectionLength} to range of selection
set {locLines, selectionLines} to line range of selection
set looseSelect to 0
-- whole lines select
if (selectionLines is greater than or equal to looseSelect as number) then
set line range of selection to {locLines, selectionLines}
set {locLength, selectionLength} to range of selection
end if
-- ignore last line break
if contents of selection ends with "
" then set range of selection to {locLength, selectionLength - 1}
-- get contents
set theSelection to contents of selection
if (selectionLength ≥ 2) and (rich text 1 thru 2 of theSelection is equal to "##") then
set contents of selection to rich text 2 thru -1 of theSelection
end if
end tell
end if
end tell