Need complicated macro help

I am trying to figure out if a couple of things I want to do with macros is at all possible.

FIRST OF ALL
I currently have this macro for targeting units so I can find them more easily.

/tar [name here]
/cleartarget [dead]
/script SetRaidTarget(“target”, 8)
/run UIErrorsFrame:Clear()

Basically it allows me to put any mob name in there and mark it with a skull so I can just look around and see if there is a skull anywhere.

The first thing I want to do is make it able to mark a second unit but only if the first unit can’t’ be found.

Obviously I could do:
/tar unit 1
/cleartarget [dead]
/script SetRaidTarget(“target”, 7)
/tar unit 2
/cleartarget [dead]
/script SetRaidTarget(“target”, 8)
/run UIErrorsFrame:Clear()

Which I do use at times, but my problem with this is that it doesn’t necessarily let me know if target 1 was found and marked. So I would like to be able to search for target 1, if target 1 exists mark it, if target 1 doesnt exist then search for target 2 and mark it.

I have tried using /tar [unit] in chat while I am currently targeting something else, and it wont switch off of that target if the thing I am trying to /target doesn’t exist… but for some reason when you do it in a macro it doesn’t work.

if I try:
/tar unit 1
/tar unit 2
/cleartarget [dead]
/script SetRaidTarget(“target”, 8)
/run UIErrorsFrame:Clear()

it will only ever search for unit 2. It will not mark unit 1 if unit 2 doesn’t exist.

SECOND
Is it possible to edit a macro with another macro or in the chat box without opening up the macro screen?

Ideally I would like a macro that I can use to take my current target and edit it into my targeting macro instead of needing to open up the macro screen and edit the target macro every time I want to search for something new. Is it possible to use some script command to edit the macro? Like a chat script to pull my current target and edit macro “macro name” line 1 to “/tar new target” or edit macro slot 1 line 1 to “/tar new target”.

If that isn’t possible is there something I can type into the chat box to edit the macro myself without needing to open the macro screen?

Not sure if that is clear or not. If you need clarification I can try to answer questions.

If none of this is possible then that’s cool too. Not a monumental issue, just figured it would be a nice quality of life thing.

No one has any information?