I had to cut some corners in order to get it to fit in a macro. The size constraint is 255 characters.
Code:
#showtooltip
/cast [@mouseover] Power Infusion
/run local s,u,f="Power Infusion","mouseover",SendChatMessage;if IsSpellInRange(s,u)==1 then local n=UnitName(u);local m=("%s cast on %s"):format(s,n);f(m,"WHISPER",nil,n);f(m,"YELL");end
Notes:
- IsSpellInRange() already does target validation checks such as existence, friend/foe, and living. It returns nil for invalid units and 0/1 based on range otherwise.
- The /cast command will always try to cast Power Infusion since it doesn't have any actual conditions to check, just a target parameter. This made specifying it for #showtooltip redundant.
- [@mouseover] is shorthand for [target=mouseover]
- /run is a shorter alias for /script.