So, @noisneil, here is an outline of how I would approach this.
Before running the macro:
Open the Project Settings for the current project and make sure that “Use musical grid” is set “off”. This is to make sure that we will have the right format in the marker list.
Save the project. This first version of the macro would clear all the project’s markers and you might want to be able to return to them easily.
Select the desired range with the marquee tool.
The macro would do this:
Select the “Open Marker List” menu item.
Select all, delete and then close the window.
Select the menu item ‘Create Marker for Region/Marquee Selection’.
Select all (just one item!) and copy.
The clipboard now contains the start time (ending in three digits after the decimal point—those are the samples, right?), the text “Marker 1” and the length of the sample, so use search regular expression to extract the start time and the length into variables.
Mathematics!
Does that seem worth a try, or provide any inspiration?
Then all I have to do is close that pane and undo the marquee cut. Doing this programatically doesn't seem worth it, due to Logic's AppleScript pernicketiness. I know what you're thinking; I could open the Audio File Editor window, right? Well, oddly enough, the sample length field is often blank there. No idea why!
So I appreciate the effort, and I'm sure it will be very helpful for other use-cases, but I think this little workaround will do the job for me without having to deal with Markers etc.