For the initial retrun in a frame, in the genereic sense that may not be doable. It depends on if the this is the first frame in a story or someplace in the middle or the last frame in a thread. Anywhere but the very beginning of the story is problem, I think, as that's just another empty paragraph in the flow of text and might not be at the top of the frame if the previous frame had a differnt size or the text was edited. How do you distinguish that from a blank paragraph in the middle of a frame that you wanted to keep (if you did in fact want to keep an empty paragraph at all)? On the other hand, if you remove consecutive returns, as the sample script does, it will take care of that case, leaving only a blank return or returns at the beginning of a story to worry about. You can find those using \A\r+ and replace with nothing. \A is the beginning of story location marker.
(?<=~a)\r+ will find paragraph returns (or multiple returns) that follow an anchored object marker. But be warned that this is not an expression with which you should be using Change All unless there are NO cases in which you have objects anchored as the last character in your paragraphs. In such cases this would cause the following paragraph to be run in with with the paragraph containing the anchored object. Maybe you could explain a little more about what you need to do here.
Thanks very much for this Peter.
Your two solutions work perfectly. In the second case, the anchored objects that are followed by returns are the only anchored objects in the document, so it works fine.
One thing is puzzling me though, the first operation -- finding the returns at the start of the story -- isn't working if it's included in the Find/change support .txt document and activated using the sample scripts. I've tried it in both JS and Applescript without any luck. Applescript throws an error, and JS just ignores that line. I'll keep fiddling to see if I can work around it, but if what I've described rings a bell, please let me know.
I once tried to modify the sample script and had some similar experience. Not being a scripter I can't tell you, unfortunately, why it doesn't work in some cases, even thought the query does work in Find/Change.
You might take a look at Peter Kahrels chaining script at http://www.kahrel.plus.com/indesign/grep_query_manager.html
Thanks again for your help Peter. I guess one manual find-and-replace isn't going to kill me!