In this case create location
might be better than create record with
as you could create groups and sub groups in one go. Make sure that slashes in your sub group names are escaped! Select the record containing the group names, run the script and you’re done.
-- Create groups based on selected text record
property theSubGroup_Locations : "1
1/1.1
1/1.1/1.1.1
2
2/2.1
This group name contains a \\/ and \"quotes\"
"
tell application id "DNtp"
try
set theSelection to selection of viewer window 1
if theSelection = {} or ((count theSelection) > 1) then error "Select one record."
set theRecord to item 1 of theSelection
set theText to plain text of theRecord
if theText = "" then error "Select a record with text."
set theGroupNames to paragraphs of theText
set theGroup to display group selector "Create groups in:"
set theGroup_Location to (location of theGroup & name of theGroup) as string
set theSubGroup_Locations to paragraphs of theSubGroup_Locations
repeat with thisGroupName in theGroupNames
if thisGroupName contains "/" then set thisGroupName to my replace_String(thisGroupName, "/", "\\/ ")
set thisGroup_Location to (theGroup_Location & "/" & thisGroupName) as string
set thisGroup to create location thisGroup_Location
repeat with thisSubGroup_Location in theSubGroup_Locations
create location (thisGroup_Location & "/" & thisSubGroup_Location) as string
end repeat
end repeat
display notification "Groups created"
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
on replace_String(theText, oldString, newString)
local ASTID, theText, oldString, newString, lst
set ASTID to AppleScript's text item delimiters
try
considering case
set AppleScript's text item delimiters to oldString
set lst to every text item of theText
set AppleScript's text item delimiters to newString
set theText to lst as string
end considering
set AppleScript's text item delimiters to ASTID
return theText
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't replaceString: " & eMsg number eNum
end try
end replace_String