I’m pretty sure that BBEdit doesn’t have a builtin command to solve this specific need. (That’s an awfully specialized task.) But it would be a trivial project to write an AppleScript, or a Perl script, or a Swift program, or probably even a shell script, which would do the job, and could even be invoked from the BBEdit Script Menu if you wanted,
I’ve appended below an AppleScript which does a vaguely related task, just to illustrate a few of the techniques in play. Obviously, your particular task would need to include “open the list of records and read lines from it.”
(* Make New Case
This script will create a new case in the Wilton ZBA web site( as represented
by the ZBA BBEdit project). It can be run standalone, but is expected to be
used from in the BBEdit scripts folder.
The script creates the case folder subdirectory of the cases/ directory. Inside
that folder, it creates a stub case.txt file and an index.html, complete
all with the persistent includes needed if the case is simple enough to rely
entirely on automatic notice generation.
Finally, it activates BBEdit and opens the new case.txt file.
*)
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on run {}
set casesFolder to getCasesFolder()
if casesFolder is missing value then return
set newCaseCreated to false
repeat until newCaseCreated
set caseRecord to getCaseIDFromUser()
set {|date|:caseDate, |number|:caseNumber, |id|:caseID} to caseRecord
tell application "System Events"
if exists folder caseID of casesFolder then
display alert ¬
("Case " & caseDate & "-" & caseNumber & " already exists") buttons {"Cancel", "OK"} default button "OK"
else
set caseFile to my makeNewCase(casesFolder, caseDate, caseNumber, caseID)
my openCaseFile(caseFile)
return
end if
end tell
end repeat
end run
(* Ask the user for a case identifier. If they enter a valid string, return
a record {date: "m/d/y", num: "n", id: "yyyymmddnn"}. If they cancel,
just let the script terminate.
*)
to getCaseIDFromUser()
set parsedCaseID to missing value
repeat until parsedCaseID ≠ missing value
set caseID to text returned of (display dialog ¬
"Enter a new case number in the format \"m/d/y-n\"" default answer ¬
"" buttons {"Cancel", "OK"} ¬
default button ¬
"OK" cancel button ¬
"Cancel" with title "Case ID")
set parsedCaseID to parseCaseID(caseID)
end repeat
end getCaseIDFromUser
(* Given a case id string of the form "m/d/y-n", return a
record {|date|: "m/d/y", |number|: "n", |id|: "yyyymmddnn"}.
If the string does not have the required format, return
missing value.
*)
to parseCaseID(param)
try
-- Split "m/d/y-n" into "m/d/y" and "n"
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "-"
set dateAndNumber to param's text items
set AppleScript's text item delimiters to tid
if (count dateAndNumber) ≠ 2 then error
-- Split "m/d/y" into "m", "d", and "y"
set AppleScript's text item delimiters to "/"
set dateComponents to text items of item 1 of dateAndNumber
set AppleScript's text item delimiters to tid
if (count dateComponents) ≠ 3 then error
-- Validate "m", "d", "y", and "n"
set n to checkNumber(item 2 of dateAndNumber, 99)
set m to checkNumber(item 1 of dateComponents, 12)
set d to checkNumber(item 2 of dateComponents, 31)
set yn to item 3 of dateComponents as integer
if yn ≥ 0 and yn < 50 then
set yn to yn + 2000
else if yn ≥ 80 and yn ≤ 99 then
set yn to yn + 1900
else if yn < 1980 or yn ≥ 2050 then
error
end if
set y to yn as text
-- Construct the return values
set caseDate to m & "/" & d & "/" & y
set caseNumber to n
set caseID to y & d2(m) & d2(d) & d2(n)
return {|date|:caseDate, |number|:caseNumber, |id|:caseID}
on error
return missing value
end try
end parseCaseID
(* If x is a string representing an integer in the range [1, max], then
return it (stripping any leading zeros); otherwise, throw an error.
*)
on checkNumber(x, max)
set n to x as integer
if n < 1 or n > max then error
return n as text
end checkNumber
(* Transform n (presumably a string of digits representing a number)
to a two-character string by removing excess leading characters
or adding leading zeros.
*)
on d2(n)
return text -2 through -1 of ("00" & n)
end d2
(* Get a folder object representing the ZBA web site folder.
Returns missing value if the folder is not available.
*)
on getCasesFolder()
tell application "BBEdit"
try
set project to project document "ZBA.bbprojectd"
on error
display alert ¬
"The ZBA project is not open in BBEdit" as warning message ¬
"Open the ZBA project and try again" buttons "OK" default button "OK"
return missing value
end try
set site to project collection "Site" of project
set sitePath to site as string
end tell
tell application "System Events"
set casesPath to sitePath & "cases"
set cases to folder casesPath
return cases
end tell
end getCasesFolder
on makeNewCase(casesFolder, caseDate, caseNumber, caseID)
tell application "System Events"
set caseFolder to make new folder at casesFolder with properties {name:caseID}
set caseFile to make new file at caseFolder with properties {name:"case.txt"}
open for access caseFile with write permission
write ("Case: " & caseID & return & ¬
"Lot: <#LotNumber#>" & return & ¬
"Address: <#Address#>" & return & ¬
"Owner: <#Owner#>" & return & ¬
"Appeal: <#Appeal#>" & return & ¬
"Purpose: <#Purpose#>" & return ¬
) to caseFile
close access caseFile
set indexFile to make new file at caseFolder with properties {name:"index.html"}
open for access indexFile with write permission
write ("<!-- #bbinclude \"Case Header-html5\" #ID#=\"" & caseID & ¬
"\" #DATE#=\"" & caseDate & ¬
"\" #NUMBER#=\"" & caseNumber & ¬
"\" --><!-- end bbinclude -->" & return & ¬
"<!-- #bbinclude \"case_summary\" --><!-- end bbinclude -->" & return & ¬
"<!-- #bbinclude \"case_page_hearing\" #MEETING#=\"all\" --><!-- end bbinclude -->" & return & ¬
"<!-- #bbinclude \"Case Footer-html5\" --><!-- end bbinclude -->" & return ¬
) to indexFile
close access indexFile
end tell
return caseFile
end makeNewCase
on openCaseFile(caseFile)
tell application "System Events" to set caseFilePath to caseFile's path
tell application "BBEdit"
activate
open file caseFilePath opening in window of project document "ZBA.bbprojectd"
select insertion point before text 1 of front window
end tell
end openCaseFile