Script Help

I’ve been using a simple macro to toggle showing and hiding some UI elements.

/run local m=ObjectiveTrackerFrame if m:IsShown()then m:Hide()else m:Show()end

While it does what I need, I run into taint issues especially with my macro for the Objective Tracker Frame. Looking at this post, it looks like it would be better to toggle the alpha instead of show/hide, but my scripting skills are terrible, and I’m not sure how to go about it.

/run ObjectiveTrackerFrame:SetAlpha(ObjectiveTrackerFrame:GetAlpha() > 0 and 0 or 1)

The problem with that is you can still interact with the frame while it is “hidden” which is likely to cause confusion.

Possibly better might be to toggle the frames collapse/expand.

/run if ObjectiveTrackerFrame.collapsed then ObjectiveTracker_Expand() else ObjectiveTracker_Collapse() end
1 Like

Thank you!

I’ve considered that, but I don’t think my cursor spends much time idle in that part of my screen. I’d prefer not to even have the little “objective” title up when hidden. I do appreciate the alternative option though it if turns out I’ve underestimated the amount of time my cursor spends in that area.

For a taint-proof method to toggle secure frames, the following sets up a button so you can toggle the objective tracker with this in a macro:

/click ToggleObjectiveTracker
-- creates a button to use in macros to toggle objective tracker securely:
-- /click ToggleObjectiveTracker
local function setup()
    local f = CreateFrame("Button","ToggleObjectiveTracker",ObjectiveTrackerFrame,"SecureHandlerClickTemplate")
    f:SetAttribute("_onclick",[[
        local p = self:GetParent()
        if p:IsVisible() then
            p:Hide()
        else
            p:Show()
        end
    ]])
    -- turn off objective tracker when logging in
    f:Execute([[ self:GetParent():Hide() ]])
end

-- Blizzard_ObjectiveTracker is a load-on-demand module and theoretically may
-- not be loaded when this loads
if ObjectiveTrackerFrame then -- it's loaded, set up button
    setup()
else -- it's not loaded, set up an event to watch for it
    local f = CreateFrame("Frame")
    f:RegisterEvent("ADDON_LOADED")
    f:SetScript("OnEvent",function(self,event,addon)
        if ObjectiveTrackerFrame then
            setup()
            self:UnregisterEvent("ADDON_LOADED")
        end
    end)
end

Paste it into https://addon.bool.no/ to turn it into an addon.

(If you log in and Blizzard_ObjectiveTracker is not loaded but it loads during combat, this will fail, but that’s probably a very rare edge case.)

edit: I don’t mess with the objective tracker much (it’s a scary behemoth), but all bets are off if the UI does some frame management stuff and shows it on its own later.

2 Likes