Register for ADDON_LOADED so you can execute the code when the talent UI loads.
Lua Code:
local f=CreateFrame("frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent",function(self,event,addon)
if addon=="Blizzard_TalentUI" then
PlayerTalentFrameSpecializationSpecButton1:SetScript("OnDoubleClick",function()SetSpecialization(1)end)
PlayerTalentFrameSpecializationSpecButton2:SetScript("OnDoubleClick",function()SetSpecialization(2)end)
PlayerTalentFrameSpecializationSpecButton3:SetScript("OnDoubleClick",function()SetSpecialization(3)end)
end
end)