Itunes: Expand & Close Playlist folders

Does anyone know how to write a script that will open/expand the currently selected Playlist folder in ITunes? The script needs to be smart enough to “do nothing” if the selected item is not a folder. Also how to script closing the current selected folder?

Many thanks - I’ve really struggled with this one - doesn’t even seem to be any keyboard shortcuts I could script using GUI scripting?:frowning: HJ

Thanks Jacques - much appreciated. Both scripts work really well!