Copy calculated bpm data from algoriddim djay to iTunes using Applescript

It’s been a long time since I’ve messed with Apple­script.

I mod­i­fied a script I found on the algo­rid­dim forums. This script would run through all tracks that were ana­lyzed in djay and try to write the bpm data to the mp3 tag in iTunes. If your library is large, this could take days.

My mod­i­fied script will take the cur­rent­ly select­ed tracks in iTunes and look for bpm data in the djay meta­da­ta plist file. Poten­tial­ly a much small­er and more focused task.


[UPDATED 29 Feb 2012] I have includ­ed sup­port for man­u­al­ly-set bpm val­ues, which are stored by djay in a sep­a­rate plist file.


[UPDATED 29 Mar 2012] I have includ­ed sup­port for copy­ing key data to iTunes, with trans­la­tion of djay’s inte­ger val­ue to string rep­re­sen­ta­tion


[UPDATED 23 Dec 2012] Bug­fix: reset bpm vari­ables in script to pre­vent old val­ues from being held in mem­o­ry for the next track. Thanks, Kieron Thor­pe!


[UPDATED 22 Jan 2013] Bug­fix: tracks with a key of 8B‑C were being skipped. Thanks, recolton­Robert!
Enhance­ment: warn user if no tracks are select­ed in iTunes.


Down­load “Get bpm and key from Djay.scpt”

51 Replies to “Copy calculated bpm data from algoriddim djay to iTunes using Applescript”

    1. Thanks for the script, Mum­bler. Saw your post­ings on the djay forum.

      I’m try­ing to mod­i­fy your bpm script to trans­fer key data into the Group­ings field in iTunes. Seems only a few para­me­ters would have to be changed, such as chang­ing BPM to KEY for the code lines that refer to the djay plist.

      What parameter(s) need to change on the iTunes side of the code?

      Thanks so much!

    2. The above would replace the group­ing field, so if you want­ed to pre­serve exist­ing data you would have to read the tag and do some string con­cate­na­tion:

      set old­Group­ing to group­ing of myTrack
      set group­ing to old­Group­ing & ” ” & myKey­Da­ta

  1. Edmond,

    Thanks for the info. I’ve edit­ed your script to copy over key data instead of bpm. It copies the key into the Group­ings field in iTunes. As writ­ten, it will over­write exist­ing Group­ing data.

    Here’s the script:

    It records the key data in the form record­ed by djay, which are val­ues from 0 to 23. Once the data is in iTunes, it is easy to group togeth­er all songs with the same key val­ue and do a batch change to a for­mat more use­ful for har­mon­ic mix­ing, such as 1A‑G#m.

    Here’s how the djay key val­ues cor­re­late to key names:

    It would be nice to work this con­ver­sion into the script to avoid this man­u­al step in iTunes. I’m kind of an Apple­script new­bie — any sug­ges­tions for how to code this? Some kind of “if-then”? If you give me the code for doing one (exam­ple: 9 = 12A‑C#m) then I can go from there for doing the oth­er 23 val­ues.

    I’d like to see this script post­ed to the fol­low­ing djay forum, either as is or with the pro­posed addi­tion, since it offers the alter­na­tive approach of select­ing the tracks in iTunes rather than doing a batch process on the whole djay cached plist.

    Thanks again!

    1. Nice, Rob!

      I incor­po­rat­ed your script and sug­ges­tions. I will update the post with the new script.

      FYI, I han­dled the con­ver­sion to text by using a list (Apple­scrip­t’s ver­sion of an array). I just set up a list:
      set all_keys to {“8B‑C”, “8A-Am”, “3B-Db”}

      Then when I have the inte­ger val­ue from djay, I use that to grab the one I want:
      set key_djay_string to item (key_djay + 1) of all_keys

      The +1 is nec­es­sary because Apple­script does not start index­ing at 0 but at 1. So for a key_djay of 0 we want item 1 of the list.

  2. Awe­some! This will save me lots of time for new music I’m bring­ing into my library. Real­ly appre­ci­ate the help, and thanks for post­ing to djay forum.


  3. hi ed,

    i found your scripts just recent­ly after hav­ing upgrad­ed to itunes 11.
    keys work per­fect­ly, but bpm does­n’t.
    it just gives rub­bish val­ues like 10x 312 then 15x 64 then 10x 67 … def­i­nite­ly nei­ther the auto-bpms of djay nor the ca. one third man­u­al bpms i did there.
    i’m not real­ly able to understand/edit the code of apple-scripts.
    do you plan to write an update for itunes 11 and make it avail­able for down­load here again? would be very great!!

    all the best, roland

  4. Strange. I have not been able to repli­cate the bpm error. Just in case, I am upload­ing the ver­sion of the script from my hard dri­ve. Please try down­load­ing again and try­ing with iTunes 11.

  5. Hi, I was also get­ting false bpms. After a bit of dig­ging I tracked it down to the round­ing rou­tine. I fixed it by doing the round­ing once, AFTER choos­ing between the man­u­al or auto bpm. Like so:

    set bpm_djay to manual_bpm_djay
    on error
    set bpm_djay to auto_bpm_djay
    end try

    if (bpm_djay is not 0) then
    — write bpm data:
    set bpm of theT to (round bpm_djay round­ing to near­est)
    end if

    Seems to work now. Kin­da proud of myself TBH since this is my first attempt at Apple­script. Record­ing Excel macros is as far as I’ve got until now : )

    1. I spoke too soon! It seems to fall over when­ev­er it gets to a track with a man­u­al­ly set BPM, copy­ing that val­ue to the next track. Gonna do some more dig­ging.…

  6. Thanks, Kieron!

    I updat­ed the script to only round the final bpm_djay val­ue, as you demon­strat­ed.

    I also added a few lines to reset the vari­ables to zero to hope­ful­ly pre­vent bpm val­ues mak­ing it into the wrong tracks.


  7. works! works! works!!! that’s a nice christ­mas gift!!!
    thanks to you both ed and kieron!
    and have some nice x‑mas hol­i­days & a hap­py new year!
    all the best, roland

  8. I hate to seem like a noob here but I real­ly want to get this work­ing for me so I fig­ured it does­n’t hurt to ask. I won­der if you could go through the steps to run­ning this please? Do you want DJay and/or iTunes to be run­ning at the same time or should they be closed? I opened the script in Apple­Script Edi­tor and hit run. It prompts me to chose key or bpm and also if I want to over­write exist­ing iTu­ines data. I make my selec­tions, then in the event log it seems like it stops with “end tell
    tell appli­ca­tion “iTunes”
    get selec­tion
    –> {}
    end tell”

    I don’t know if it is work­ing or not or what is going on. Any clar­i­fi­ca­tion would be appre­ci­at­ed.

    1. Hel­lo,

      To run this script you should have iTunes open and one or more tracks select­ed. The script will per­form its actions on the select­ed tracks only.

      Per­haps I should pop up a warn­ing when no tracks are select­ed? That may make it more clear that noth­ing hap­pened.

      Also, here are some tips for mak­ing scripts avail­able in the iTunes scripts menu:


  9. I lit­er­al­ly just fig­ured that out after a few days of going bonkers try­ing to deci­pher the script and fig­ure out what was wrong. I was only get­ting one track to update but then I had a “eure­ka!” moment. I then select­ed all tracks and now it is doing its thing work­ing like a charm! Amaz­ing! I do think a pop-up remind­ing about track selec­tions would be help­ful. It sure would have saved me a lot of time and headache. Not that I am com­plain­ing or any­thing. Again, great work to all that con­tributed to this.

  10. Hap­py New Year! I had this work­ing just great. I was select­ing chunks at a time and run­ning the script. Even­tu­al­ly it stopped actu­al­ly writ­ing to iTunes. First it was just kick­ing out an “error ‑10004” over and over. I did a per­mis­sions tweak.

    Now it keeps giv­ing me “error num­ber ‑1728”

    I would copy and past the lines around it but for some rea­son I can­not copy them. That also seems odd.

  11. Not any more. I end­ed up reboot­ing and that seems to have fixed it. Odd, I know. It is work­ing though as I type this. I have a large library (35,000+) so I am doing it in chunks. I did notice one thing. I’ll try it again to con­firm but, if I recall cor­rect­ly, after choos­ing both BPM and Key, when I then choose to not over­write iTunes info, it skips that track total­ly. This only was a thing when I already had BMP filled in on tracks and fig­ured by not over­writ­ing it would just fill in the Key. Not sure if that actu­al­ly makes sense since it is ear­ly and I have only had a sip of cof­fee. In the end, for tracks that already had BPM, I chose to over­write so it would fill in both.

  12. Tried this script again and it seems to have worked per­fect­ly. The errors I was get­ting before Christ­mas (even AFTER the round­ing adjust­ment I sug­gest­ed) aren’t hap­pen­ing any more. Nice work Edmond & MacPin­guin!

  13. Hey there — just drop­ping by to say thanks for this script! I also found my way here through the djay forums, and I’ve got the script work­ing its way through my playlists, run­ning like a charm. Much appre­ci­at­ed!

  14. Hi Edmon,

    Thanks for post­ing the script. I have used in exten­sive­ly. There are a cou­ple of prob­lems I am hav­ing with it, but am able to work around them

    1. The first “8B‑C” does not post to the meta tag. To get around this, I run a playlist of about 1,000 songs, what is left is 8B‑C. I just group edit them.

    2. Apple script con­stant­ly reports “Not Respond­ing” which I ignore, but my lap­top crawls through a playlist when this hap­pens. I close both iTunes and Djay con­stant­ly after run­ning a cou­ple of 1,000 songs and reboot.

    Ist there any way to speed up the script? Have one just for BPM with­out the extra code for Key? And vice-verse. I have 8GB ram and a hybrid dri­ve. For a three year old Mac­book Pro, it is fair­ly fast.

    I have about 61,000 songs in cur­rent library.

    Thanks again, Robert

    1. Hi Robert,

      First of all, thanks for point­ing out the “8B‑C” bug. I have updat­ed the script.

      Unfor­tu­nate­ly, Apple­script is not known for its effi­cien­cy or speed. I would sug­gest cut­ting back your batch size until you find a bal­ance between respon­sive­ness and con­ve­nience that you deem accept­able.

      You can run the script in BPM-only or Key-only mode and the script will skip over those parts of the code.

      Are you run­ning the script from the iTunes script menu?


  15. I’ve edit­ed it to put it in the com­ments instead of group­ing (for trak­tor) and put equal spac­ing between the num­ber and the actu­al key so it’s a lit­tle eas­i­er to see quick­ly.

  16. Thanks a lot, Ed.

    it works fine in a Mini with 10.6.8 , iTunes 10 and Djay 4.1
    Your post in the old Djay forum brought me there. It´s a pity that the new ones suck so much.

  17. Thanks for this the BPM ele­ment is per­fect.

    I just have a query regard­ing the key, and sor­ry if it is a dumb ques­tion but my knowl­edge of “real” music is a bit crap.

    In DJAY the key for a track is: Gb (i assume that is G flat), but in itunes in the group­ing filed it says 2A-Ebm.

    Thanks in advance for any enlight­en­ment!

  18. ok!
    For me, all Groups Fields are filled yet. All BPM ready, cal­cu­lat­ed in DJay, BPM emp­ty in iTunes, tests done track by track… itunes BPM not filled… ?
    My iTunes Library is so 90% analysed by DJay (?)

    Best regards.

  19. Hi dmsr,

    Since André is report­ing that the script works with 11.1 on his sys­tem I would sug­gest try­ing either a reboot of your sys­tem or using Disk Util­i­ty to repair per­mis­sions. Or both.


  20. I stum­bled across your awe­some work, whilst search­ing for a way of get­ting djay bpm data to copy into iTunes track info and you seem to have done it! But I have no real tech skills and I don’t know how to run your script?!!! Do I lit­er­al­ly down­load it and “open with” iTunes, or is there more too it? I should men­tion my iTunes is on a PC not a Mac — does that mat­ter. Are there any djay set­tings that need adjust­ing to allow the data to be shared? If you have a mo to post an idiots guide it’d be great. Thanks bud­dy. Ronb

  21. Thank you so much for this won­der­ful script. Some­times in djay, the auto bpm will give a val­ue that is half the actu­al bpm, which I rem­e­dy by click­ing ‘dou­ble.’ These bpm val­ues are not trans­fer­ring to iTunes. Instead it’s giv­ing me the ‘auto’ val­ue of one half the cor­rect num­ber. Any thoughts as to what’s going on?

  22. I have this prob­lem to. I use a lot of old music when I dj, and djay’s cal­cu­lat­ed bpm val­ue is almost always half of the the actu­al bpm. There­fore I go through each new song after it’s been import­ed to djay and dou­ble their bpm val­ue. When I use the script, how­ev­er, djay’s ini­tial val­ue is copied instead of the dou­bled, cor­rect, val­ue.

  23. Oops, post­ed on the wrong place, so I repost it here aswell.

    I have this prob­lem to. I use a lot of old music when I dj, and djay’s cal­cu­lat­ed bpm val­ue is almost always half of the the actu­al bpm. There­fore I go through each new song after it’s been import­ed to djay and dou­ble their bpm val­ue. When I use the script, how­ev­er, djay’s ini­tial val­ue is copied instead of the dou­bled, cor­rect, val­ue.

  24. Same prob­lem with wrong half speed bpm. For me as swing dj, it´s not pos­si­ble to use the script. An update would be fan­tas­tic!

  25. Good news every­one!

    Here is a brand new ver­sion of djay2itunes — now with day Pro sup­port!

    Source code (now JavaScript) and appli­ca­tion avail­able on GitHub:

    (Note: open with right-click -> Open, because app is not signed)

    How to use this:

    Text is in Russ­ian, but pic­tures can tell every­thing 🙂

    Have a nice day!

This site uses Akismet to reduce spam. Learn how your comment data is processed.