validate toolbar item dont work

first sorry for my bad english.
i have a script to resize main window value to custom window and validate buttons on toolbar when i click on it, but the validate function dont work :frowning: please help me solve this problem. thanks.

script toolbarWindow
    property parent : class "NSWindow"
    property FinderView : missing value
    property DockView : missing value
    property AboutView : missing value
    property UpdatesView : missing value

    on switchView_(sender)
        set tagNumber to tag of sender as real
        if tagNumber is 10 then
            set targetView to FinderView
            else if tagNumber is 20 then
            set targetView to DockView
            else if tagNumber is 1 then
            set targetView to AboutView
            else if tagNumber is 3 then
            set targetView to UpdatesView
        end if
        set contentView to contentView() of me
        repeat with aView in subviews of contentView
            tell aView to removeFromSuperview()
        end repeat
        set windowFrame to frame() of me
        set newWindowFrame to frameRectForContentRect_(frame() of targetView) of me
        set frameHeight to height of |size| of windowFrame - height of |size| of newWindowFrame
        set x of origin of newWindowFrame to x of origin of windowFrame
        set y of origin of newWindowFrame to y of origin of windowFrame + frameHeight
        tell me to setFrame_display_animate_(newWindowFrame,1,1)
        tell contentView to addSubview_(targetView)
    end switchView_
    on validateUserInterfaceItem_(anItem)
        set theSel to anItem's tag() as text
        --set theSel to anItem's action() as text
        if theSel = "10" and contentView() is FinderView then
            return false
            else if theSel = "20" and contentView() is DockView then
            return false
            else if theSel = "1" and contentView() is AboutView then
            return false
            else if theSel = "3" and contentView() is UpdatesView then
            return false
            return true
        end if
    end validateUserInterfaceItem_

end script


NSToolbar has its own validateToolbarItem_() method.

Note: NSToolbarItem’s validate method calls this method only if the item’s target has a valid action defined on its target and if the item is not a custom view item. If you want to validate a custom view item, then you have to subclass NSToolbarItem and override validate.

yes i have subclass NSToolbarItem and even if i use validateToolbarItem, it also does not work, can you check my project and modify it for me. thanks.

when you add the line

log theSel

in the validateToolbarItem_() method after retrieving the tag you will see that it’s called properly.

Did you read the note? validateToolbarItem_() is not called if the toolbar has no valid action defined