Skip to main content
CarlosCanto
Community Expert
Community Expert
October 15, 2014
Answered

How to create an Empty Playlist File on Mac?

  • October 15, 2014
  • 1 reply
  • 1316 views

Hello everyone, I'm working on a Music Player script, I was able to play a file via the default player as when we doubleclick on a file. The problem is I have no control over the Player, so to "stop" a file I could play a "silent" mp3, one with 1 second of silence in it for example. I discarded the idea since I had to distribute this silent.mp3 file along with the script. A better option is to play a "playlist", since playlist files are text only, I could create them an empty playlist file on the fly...

so, the question is, what's the default playlist extension on a mac? and how to create one on the Mac?

in windows the default player is Windows Media Player, the default playlist file extension is *.wpl.

here's the contents of an empty playlist

<?wpl version="1.0"?>

<smil>

    <head>

        <meta name="Generator" content="Microsoft Windows Media Player -- 12.0.7601.18150"/>

        <meta name="ItemCount" content="0"/>

        <title>empyPlaylist</title>

    </head>

</smil>


here's the script, so far Windows only, at least to stop the file being played.

//  script.name = musicPlayer_Windows.jsx;

//  script.needs = I need to create an Empty Playlist File for the Mac, that will play on the default music player when executed

// carlos canto, 10/12/2014

var w = new Window('dialog', 'Music Player');

var btnFile = w.add('button', undefined, 'Select an *.mp3 file to play...');

var lblSong = w.add('edittext', undefined, '');

lblSong.characters = 30;

var btnPlay = w.add('button', undefined, 'Play');

var btnStop = w.add('button', undefined, 'Stop');

var btnClose = w.add('button', undefined, 'Close');

btnPlay.enabled = btnStop.enabled = false;

var emptyPlaylist = getEmptyPlaylist ();

btnFile.onClick = function () {

    var file = File.openDialog ("Select File to Play...", '*.mp3', false);

    lblSong.text = file.displayName;

    lblSong.file = file;

    btnPlay.enabled = btnStop.enabled = true;

}

btnPlay.onClick = function () {

    lblSong.file.execute();

    $.sleep (300);

    BridgeTalk.bringToFront('estoolkit');

}

btnStop.onClick = function () {

    emptyPlaylist.execute();

    $.sleep (300);

    BridgeTalk.bringToFront('estoolkit');

}

btnClose.onClick = function () {

    w.close();

}

w.show();

// this function creates an Empty Playlist file (Windows) on the fly, this file will be used to "stop" a playing file

// I need a similar function for Mac

function getEmptyPlaylist () {

    var desk = Folder.desktop;

    var f = new File(desk+'/emptyPlaylist.wpl');

    if (!f.exists) {

        var s_emptyPlaylist = (new String("<?wpl version=\"1.0\"?>\n<smil>\n    <head>\n        <meta name=\"Generator\" content=\"Microsoft Windows Media Player -- 12.0.7601.18150\"/>\n        <meta name=\"ItemCount\" content=\"0\"/>\n        <title>empyPlaylist</title>\n    </head>\n</smil>\n"));

        f.encoding = 'utf-8';

        f.open('w');

        f.write(eval(s_emptyPlaylist));

        f.close();

    }

    return f;

}

  

thanks in advance

Carlos

This topic has been closed for replies.
Correct answer Dirk Becker

iTunes wouldn't let me export an empty playlist.

The following three lines is the .m3u playlist of the previously mentioned track:

#EXTM3U

#EXTINF:179,Aquarella - Georges Arvanitas Trio

/Users/dirk/Music/iTunes/iTunes Media/Music/Georges Arvanitas Trio/Jazz Loves Paris By Night - Piano & Hammond Organ/02 Aquarella.m4a

If I launch that playlist file, iTunes aborts the current track and plays the playlist.

If I remove lines 2+3, iTunes ignores the playlist.

If I edit line 3 to a bogus file reference, iTunes ignores the playlist.

Btw, iTunes considers the "repeat" setting - so if the track is a second of silence, it will be repeated forever.

1 reply

Legend
October 16, 2014

You can execute any music file in the default player - that's a user choice per individual file or per file type, default will be iTunes:

File("~/Music/iTunes/iTunes Media/Music/Georges Arvanitas Trio/Jazz Loves Paris By Night - Piano & Hammond Organ/02 Aquarella.m4a").execute();

That execute() should even work on a PC.

To remote control iTunes:

app.doScript('tell application "iTunes" to play track "Aquarella"',ScriptLanguage.APPLESCRIPT_LANGUAGE);

app.doScript('tell application "iTunes" to stop',ScriptLanguage.APPLESCRIPT_LANGUAGE);

Do you still need playlists?

Edit:

Having a deeper look at your code, I see you're targeting ESTK. ESTK has no app.doScript(), for there I'd just compile the single line AppleScript into a mini application and execute that.

Dirk

CarlosCanto
Community Expert
Community Expert
October 17, 2014

hmm...I think it's going to be more complicated than I thought.

correct, this script targets the ESTK, it is part of a larger Illustrator script, which doesn't have doScript either...I would go with applescript as last resort. I think going with the playlist file is easier.

based on your comment I realized users might change their default players, so on Windows I'm going to change the playlist file from *.wpl to the more universal *.m3u, I guess whatever decent player made the default, supports this file.

so, will an *.m3u playlist file play on the default mac player (itunes) when executed?

File("~/Music/iTunes/iTunes Media/Music/emptyPlaylist.m3u").execute(); // will this play on itunes?


I noticed that the *.m3u file can be blank, it will still "play" when executed() and effectively "stops" any music file currently being played...if this happens on Mac also, that's what I'm after.


thanks for helping Dirk.

Dirk BeckerCorrect answer
Legend
October 17, 2014

iTunes wouldn't let me export an empty playlist.

The following three lines is the .m3u playlist of the previously mentioned track:

#EXTM3U

#EXTINF:179,Aquarella - Georges Arvanitas Trio

/Users/dirk/Music/iTunes/iTunes Media/Music/Georges Arvanitas Trio/Jazz Loves Paris By Night - Piano & Hammond Organ/02 Aquarella.m4a

If I launch that playlist file, iTunes aborts the current track and plays the playlist.

If I remove lines 2+3, iTunes ignores the playlist.

If I edit line 3 to a bogus file reference, iTunes ignores the playlist.

Btw, iTunes considers the "repeat" setting - so if the track is a second of silence, it will be repeated forever.