Replace/Programmatically edit a Selected Action?

No, there is no “Paste Replacing Selection” option for actions. Maybe there should be, but its kind of an odd usage case. That said, it would make “Engroup” a lot easier.

What you could do would be something like:

  • Cut
  • Modify the clipboard
  • If the Copy menu item is enabled
    • Command-Option-V (Paste Above)
  • Else
    • Paste

After cutting an item, the following action, if any, will be selected. So if the Copy menu is enabled, paste above works, and otherwise, paste will append to the end which is what you want if you cut the last item.

Should work.