Actually on a mac you could just use applescript with Bill Orcutt’s [shell] external.
— Pasted Max Patch, click to expand. —
Copy all of the following text. Then, in Max, select New From Clipboard.