Opening a single playlist with Groovy

patrick.gary's Avatar


27 Aug, 2021 05:01 PM

I've been trying to programmatically create a new playlist with another larger playlist as my source.
I'm having trouble opening up a single playlist instead of working with all songs in the library. I've reviewed the code samples in the beaTunes Plugins documentation and GitHub archive, and nothing seems to show how to either open and/or access a given playlist or to write a new playlist to anything other than a file.

Do you have any code samples I could look at? I'd prefer Groovy, but can probably figure it out from anything you have laying around.

  1. Support Staff 1 Posted by hendrik on 28 Aug, 2021 10:51 AM

    hendrik's Avatar


    I just realized you are trying to program a solution for

    Before I realized that, I remembered that I had a request recently and that I could use that request to illustrate a solution for what you're asking. I guess I have just solved both issues. :-)

    Typically, you would want to extend a com.tagtraum.beatunes.action.BaseAction and then perform the desired task in the actionPerformed(event) method. This would be a perfectly valid approach. To create a new playlist, you'd do something like (Java code):

    protected PlayList createEmptyPlayList() {
        final BeaTunes application = getApplication();
        final MediaLibrary library = application.getMediaLibrary();
        final boolean isITunesLibrary = library.getLibraryDescriptor() instanceof ITunesLibraryDescriptor
                || library.getLibraryDescriptor() instanceof ITLibraryDescriptor;
        return library.createPlayList(application.getNewPlaylistParentId(), isITunesLibrary ? null : application.localize("untitled"));

    And then simply add tracks to the newly created playlist.

    To get the tracks you want, you could use the method getSelectedPlayList(), call getSongs(), filter the iterable in the way you want it, and then call something like newPlayList.addSongIds(newSongIds). Note that it's always preferable to work with ids rather than AudioSong objects.

    That all said, there is a smarter way to do it.

    Extend com.tagtraum.beatunes.action.standard.NewPlayListAction and implement fillPlayList(newPlaylist, selectedSongIds). It will take care of a couple of UI hiccups and also playlist creation. How it is done is shown in (the newly created sample) at

    Hope this helps,


  2. 2 Posted by patrick.gary on 28 Aug, 2021 10:55 PM

    patrick.gary's Avatar

    Thank you so much!I have been trying to figure out a way to automate this off and on for at least 2 years but haven't ever gotten very far.You are a life saver Sent via the Samsung Galaxy S10, an AT&T 5G Evolution capable smartphone
    -------- Original message --------From: hendrik <[email blocked]> Date: 8/28/21 5:51 AM (GMT-06:00) To: [email blocked] Subject: Re: Opening a single playlist with Groovy [Plugin #2017]

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac