title: Is there a better way to add a new playlist to iTunes through Javascript for Automation (JXA)?
body: <p>There must be a better way to create a new element in a collection (if that's what really happens behind the abstraction).</p>
  
  <p>I'm looking for the JXA equivalent of this applescript</p>
  
  <pre><code>if (count of (playlists whose name is plName)) is 0 then
    make new playlist with properties { name: plName }
  end if
  </code></pre>
  
  <p>I have tried a number of things, but can't get an equivalent. The closest I can get is to duplicate an existing playlist and then rename it...</p>
  
  <pre><code>if ( iTunes.userPlaylists.whose( { name: {_equals: plName } } ).length == 0 ) {
      mnp = iTunes.userPlaylists[0].duplicate()
      mnp.name.set( plName )
  }
  </code></pre>
  
  <p>Any hints on the cleanest way to test for a playlist's existence, or to select a playlist to duplicate are welcome. Like most people, due to the appalling lack of documentation for JXA, I'm figuring most of the application interaction stuff out by experimentation.</p>
  
  <p>My <em>main question</em> though is whether there is a way to create an empty playlist without having to duplicate one. Not that it matters I guess if I have a work around, but it just feels like a kludge.</p>