Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:42:53+00:00 2026-06-13T07:42:53+00:00

I learned how to create a playlist in a previous question, but now I

  • 0

I learned how to create a playlist in a previous question, but now I can’t figure out how to add tracks to it. Right now I have:

tracks.sort(key=lambda tup: tup[0])
i = 0
for trackList in generatePlaylists(tracks,10):
    i += 1
    playlistname = str(i)
    p = {'name': playlistname}
    playlist = iTunes.classForScriptingClass_("playlist").alloc().initWithProperties_(p)
    iTunes.sources()[0].playlists().insertObject_atIndex_(playlist, 0)

    # Find the playlist I just made
    for playlist in iTunes.sources()[0].playlists():
        if playlist.name() == playlistname:
            newPlaylist = playlist

    # Add the tracks to it
    for track in trackList:
        print track[1].name()
        iTunes.add_to_(track[1],newPlaylist)

My tracks are in a list of tuples tracks, where the first element of the tuple is a score and the second is the actual track object. generatePlaylists is an iterator which splits all library tracks into 10 lists.

The above code runs without error, but in iTunes the playlists are empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:42:53+00:00Added an answer on June 13, 2026 at 7:42 am

    First, here’s the short answer:

    track.duplicateTo_(newPlaylist)
    

    The problem is that iTunes.add_to_ sends the add command, which takes a file (alias) and imports it into a playlist; you want to send the duplicate command, which takes any object and makes another copy of the object. You don’t have a file, you have a track. (You could get a file via track.location(), but you don’t want to re-import the file, just copy the track over.)

    Also, in this case, you need to call the method on the track, rather than calling it on the app and passing it the track.

    The first half of this is hard to explain without a solid understanding of the iTunes object model (and the AE model underneath it). But you don’t really need to understand it. In most cases, by looking over the iTunes scripting dictionary (in AppleScript Editor) and trial and error (in AppleScript Editor or with py-appscript) you can figure it out what you want. (Just make sure you’re working on a scrap library, or have a backup…) In this case, the only commands it could possibly be are add, copy, duplicate, or move, so just try them all and see what they do. Or, alternatively, go to dougscripts and download a bunch of samples and find one that does what you want.

    The second half of this, figuring out how to translate to ScriptingBridge… well, I can’t explain it without going into a long rant on SB (which hhas does much better than me, if you want to read one). But the basics are this: As far as iTunes is concerned, duplicate is a command. If you give it a direct object (tell application "iTunes" to duplicate theTrack to thePlaylist) it’ll use that; if not, you’re asking the subject to duplicate itself (tell theTrack to duplicate to thePlaylist). It works exactly like English. But SB insists on an object-oriented model, where duplicate is a method on some object. So, only one of those two forms is going to work. In general, you can figure out which by just looking at dir(iTunes) and dir(track) to see which one has a method that looks like the command you want.

    As you can tell from the above, you’ve got a lot of trial and error ahead of you if you’re trying to do anything complicated. Good luck, and keep asking.

    PS, I have no idea why your code fails silently. The obvious way the add_to_ method should translate into a command should raise a -1708 error (as appscript iTunes.add(track, to=newPlaylist) or AppleScript add theTrack to newPlaylist both do…).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently learned to create dynamic links via php, but my problem today
I already learned how to create a Twig extension . But now I need
I have learned that we can't instantiate an abstract class. But today i tested
OK, so I have learned how to create a list, view items in the
I have learned from the sencha doc how to create a simple MVC application,
I learned how to create a custom Qt Widget. I have two manuals for
I've learned that views can be used to create custom table views (so to
Yesterday I learned from Bill Venables how local() can help create static functions and
I have learned a lot about EJB3.1 lately, but apparently not enough. Here's my
im trying to create a sort of playlist feature that will work on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.