Not sure why you want to spam leave/join queue but after checking the api for GetBattlegroundInfo should just be a matter of checking for the name
Code:
/click MiniMapBattlefieldFrame
/click DropDownList1Button2
/run for i=1,GetNumBattlegroundTypes()do local n, ce=GetBattlegroundInfo(i)if n=="Tol Barad" and ce then JoinBattlefield(i)end end
Basically getting the name of the Battleground, also the ce variable is for if you can enter the Bg, haven't tested but that should in theory make this only work with queue for TB is open.
The name is localized though, so if this doesn't work you might need to fix the name
Code:
/run for i=1,GetNumBattlegroundTypes()do local n=GetBattlegroundInfo(i) print(n)end
That should print out the names of all the battlegrounds, just fix the n=="Tol Barad" with the exact name printed out.