I just tried your first set of code above (after fixing the trailing | characters which I’m guessing were an artifact of pasting here and not in the original content), and it correctly switched perspectives and selected the target folder.
What it didn’t do is scroll to make that folder visible, so it wasn’t obvious that it was selected. (But the inspector was inspecting that folder, and if I scrolled down my outline to the folder I saw that it was selected.)
We don’t currently have any API to scroll to the selection, which would be useful in this example.
But one thing you could do to make that folder more prominent would be to select it in the projects sidebar, so the content outline only displays that folder and its contents. Something like:
Or you could take advantage of the fact that every database item has a URL that you can open:
selectedItem.url.open();
Calling open() on the URL will automatically switch to the Projects perspective, select the smallest scope in the sidebar that can display the item, select the item in the content outline, and scroll the content outline to display that item.
I also just submitted OG #3044329 requesting that the ‘Show in Projects’ command be made to work for folders and included in a folder’s context menu. (Which would eliminate the need for this particular automation altogether.)