https://wow.gamepedia.com/API_EditMacro
Before installing this script, create a macro called "myFavouriteMacro" and drag it to an action bar.
You can turn the script into an addon using
https://addon.bool.no/
Lua Code:
local macro1 = [=[#showtooltip
/cast Thoughtsteal]=]
local macro2 = [=[#showtooltip
/cast Shadowfiend]=]
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_PVP_TALENT_UPDATE")
f:SetScript("OnEvent", function()
EditMacro("myFavouriteMacro", nil, nil, GetSpellInfo("Thoughtsteal") and macro1 or macro2)
end)