If there's only one level of bookmarks (or you only want to use the top-most level) then you don't need a script at all.
Use the Split Document command and select "Top-Level Bookmarks" to achieve it.
Yea I found that solution, however usually I need to split by all bookmarks, not just the top level.
That is much more complicated. You would need to write a recursive function
that iterates over all of the bookmarks in the file, executing each one and
then save the current number, execute the next one, save that number, and
extract the pages between them.
The AutoBookmark plugin from EverMap (https://www.evermap.com/autobookmark.asp) can print the bookmark titles on the associated pages. See the functionality titled "Printing Bookmark Titles on the Corresponding Pages".