Thanks.
It's completely custom.
It could be adapted for another editor of course.
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2010/10/11 21:32
# dMod: 2017/02/22 19:42
# Appl: Script Debugger
# Task: Insert info header into the front script document.
# Libs: ELb, FLb, GLb
# Tags: @Applescript, @Script_Debugger, @Script, @Insert, @Attribution, @Info, @Header,
-------------------------------------------------------------------------------------------
try
set dateTime to strftime (current date) into "%Y/%m/%d %R" -- Satimage Osax
set _sep to "
-------------------------------------------------------------------------------------------
"
set headerTextTemplate to text 2 thru -1 of "
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: " & dateTime & "
# dMod: " & dateTime & "
# Appl: <apps>
# Task:
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, <tags>
-------------------------------------------------------------------------------------------
"
set myPath to (path to me as text)
if myPath ends with "Script Debugger.app:" then error "Script is NOT saved!"
tell application "Script Debugger"
-------------------------------------------------------------------------------------
# Make sure this script doesn't act on itself (must be saved).
-------------------------------------------------------------------------------------
if myPath = (get file spec of front document as text) then
set scriptDoc to a reference to document 2
else
set scriptDoc to a reference to document 1
end if
-------------------------------------------------------------------------------------
if scriptDoc exists then
tell scriptDoc
set scriptSource to its source text
if (fndBool("^# Auth.+", scriptSource, false, false) of me) = false then
--» Compile Tags for found Applications from script content:
set appList to fndUsing("^[[:blank:]]*tell application \"(.+?)\"", "\\1", scriptSource, true, true) of me
if class of appList is text then set appList to {appList}
set appList to sortlist appList with remove duplicates
set headerTextTemplate to cng("<apps>", (join appList using ", "), headerTextTemplate) of me
copy appList to tagList
if fndBool("use framework", scriptSource, false, false) of me then
set end of tagList to "ASObjC"
set tagList to sortlist tagList with remove duplicates
end if
set tagList to cng("^", "@", tagList) of me
set tagList to cng(" ", "_", tagList) of me
set tagList to join tagList using ", "
set headerTextTemplate to cng("<tags>", tagList, headerTextTemplate) of me
--» Remove trailing whitespace and separater line if it exists:
set textSelector to fnd("^\\s*----------*\\s*\\Z", scriptSource, 0, 0) of me
if (textSelector ≠ false) then
set {_matchPos, _matchLen} to {matchPos, matchLen} of textSelector
set _matchPos to _matchPos + 1 # Translate SIO to SD coordinates
set selection to {_matchPos, _matchLen}
set selection to _sep
else
--» Select insertion point at end of text.
set _len to length of scriptSource
set selection to {_len + 1, 0}
set selection to _sep
end if
--» Allow for leading whitespace at top of script:
set textSelector to fnd("\\A\\s*----------*\\s*", scriptSource, 0, 0) of me
--» Insert Header Text:
if textSelector ≠ false then
set {_matchPos, _matchLen} to {matchPos, matchLen} of textSelector
set _matchPos to _matchPos + 1 # Translate SIO to SD coordinates
set selection to {_matchPos, _matchLen}
set selection to headerTextTemplate
else
set selection to {1, 0}
set selection to headerTextTemplate
end if
end if
end tell
end if
end tell
on error e number n
stdErr(e, n, true, true) of me
end try
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on cng(_find, _replace, _data)
change _find into _replace in _data with regexp without case sensitive
end cng
-------------------------------------------------------------------------------------------
on fnd(_find, _data, _all, strRslt)
try
find text _find in _data all occurrences _all string result strRslt with regexp without case sensitive
on error
return false
end try
end fnd
-------------------------------------------------------------------------------------------
on fndBool(_find, _data, _all, strRslt)
try
find text _find in _data all occurrences _all string result strRslt with regexp without case sensitive
return true
on error
return false
end try
end fndBool
-------------------------------------------------------------------------------------------
on fndUsing(_find, _capture, _data, _all, strRslt)
try
set findResult to find text _find in _data using _capture all occurrences _all ¬
string result strRslt with regexp without case sensitive
on error
false
end try
end fndUsing
-------------------------------------------------------------------------------------------
on removeDupesFromListOfStr(theList)
set tempList to {}
set listLength to length of theList
repeat with itemNum from 1 to listLength
if itemNum ≠ listLength and (items (itemNum + 1) thru -1 of theList) contains (item itemNum of theList) then
set (item itemNum of theList) to null
end if
end repeat
return text of theList
end removeDupesFromListOfStr
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
set e to e & return & return & "Num: " & n
if beepFlag = true then
beep
end if
if ddFlag = true then
tell me
set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
end tell
if button returned of dDlg = "Copy" then set the clipboard to e
else
return e
end if
end stdErr
-------------------------------------------------------------------------------------------