TakeIf you really want to travel by train but still want to travel less than a day, then take a bus from Trieste bus station to Sezana and then a train from Sezana to Ljubljana. theThe train station in Sezana is right close to the bus onestation.
The alternative, and a longer option, is to take a bus to Koper (about 20km), and then a train from there to Ljubljana.