Benches Apps and software

8

Retrieving GrageBand Track Names

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I'm trying to retrieve each Track Name in a GarageBand project via its "Track Number" property, however the returned values are not in the expected numerical order, nor have I been able to figure out a pattern for calculating which is which. The AppleScript bit is very simple:

tell application "GarageBand"
  tell song 1
    tell track 1
      get Instrument name
      return the result
    end tell
  end tell
end tell

With only 1 track in the project named "Track 1" the above works as expected, telling me that #1 is named "Track 1"

If I add a second track, "Track 2" and run the above script for each track i get
#1 "Track 2"
#2 "Track 1"

Adding a third:
#1 "Track 3"
#2 "Track 2"
#3 "Track 1"

The above looked promising, it appeared to simply be in reverse order, but then if I add a forth track:
#1 "Track 3"
#2 "Track 4"
#3 "Track 2"
#4 "Track 1"

and a fifth:
#1 "Track 5"
#2 "Track 3"
#3 "Track 4"
#4 "Track 2"
#5 "Track 1"

Here's what gets returned from 10 tracks (which, to be clear, are in numerical order from top to bottom in GarageBand, "Track 1", "Track 2', etc):
#1 "Track 7"
#2 "Track 9"
#3 "Track 8"
#4 "Track 5"
#5 "Track 10"
#6 "Track 3"
#7 "Track 4"
#8 "Track 2"
#9 "Track 6"
#10 "Track 1"

The only constant I notice is that the physical first track in GarageBand, "Track 1" is always returned as the last value, but I can't pick out a pattern for the rest. Can anyone see a pattern I'm missing, or is there another way of retrieving the index in the same order as the GUIs layout?

8 replies

Sign in or join Beachball Help to reply.

  1. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I have tried the following script with GarageBand ’09 version 5.1 (398):

    *tell application "GarageBand" to get instrument name of tracks of song 1*

    I have added a few electric guitars one after the other, in the following order:

    Clean Combo, Country Twang , Crystal Arpeggio, Dark Vibrato, Dream Pop, Dreamy Texture, Dublin Delay.

    Here are the successive results returned by the script:

    {"Clean Combo"}
    {"Clean Combo", "Country Twang"}
    {"Clean Combo", "Country Twang", "Crystal Arpeggios"}
    {"Clean Combo", "Dark Vibrato", "Country Twang", "Crystal Arpeggios"}
    {"Clean Combo", "Dream Pop", "Dark Vibrato", "Country Twang", "Crystal Arpeggios"}
    {"Clean Combo", "Dream Pop", "Dreamy Texture", "Dark Vibrato", "Country Twang", "Crystal Arpeggios"}
    {"Clean Combo", "Dreamy Texture", "Dark Vibrato", "Country Twang", "Dublin Delay", "Dream Pop", "Crystal Arpeggios"}

    I thought I would find a solution using GUI Scripting, but I couldn't.

    However, there seems to be a constant mathematical relation between the order in which the instruments are added and the order returned by the script.

  2. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Well… Although the following script is just an +ad hoc+ solution, it seems to work flawlessly (at least on my computer with GarageBand ’09 version 5.1 (398) installed), even after manually changing the tracks order in the left column of the main window:

    --BEGINNING OF SCRIPT
    tell application "GarageBand"
    tell song 1
    set N to number of tracks
    if N < 4 then
    return instrument name of tracks
    else if N = 4 then
    return my instrumentNames({1, 3, 4, 2})
    else if N = 5 then
    return my instrumentNames({1, 4, 5, 3, 2})
    else if N = 6 then
    return my instrumentNames({1, 5, 6, 4, 2, 3})
    else if N = 7 then
    return my instrumentNames({1, 4, 7, 3, 6, 2, 5})
    else if N = 8 then
    return my instrumentNames({1, 4, 7, 3, 6, 2, 5, 8})
    else if N = 9 then
    return my instrumentNames({1, 4, 8, 3, 7, 2, 5, 9, 6})
    else if N = 10 then
    return my instrumentNames({1, 4, 9, 3, 7, 2, 5, 10, 6, 8})
    end if
    end tell
    end tell

    on instrumentNames(theList)
    tell application "GarageBand" to tell song 1
    set theNames to {}
    repeat with k in theList
    copy instrument name of track k to the end of theNames
    end repeat
    return theNames
    end tell
    end instrumentNames
    --END OF SCRIPT

    Hope it can help.

  3. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Pierre L. wrote:
    there seems to be a constant mathematical relation between the order in which the instruments are added and the order returned by the script.

    indeed, I'm sure there is, but I'm just not picking up on it yet

  4. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    i'm actually using another IDE which builds and executes the AppleScript on the fly, and it returns an execution error with the above, but it does point me in what may be a successful direction (albeit, painful with the thought of figuring out the potential 255 sets that GB can offer ... i might have to trim that down to a more reasonable number, unless i can automate some of the work)

    i'll post back with how this goes, tnx! ~~hang

  5. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Drat, still not quite there. i tested out your script in Script Editor, and in a 4 track project, named 1 through 4 I get: {"Track 3", "Track 2", "Track 1", "Track 4"}

    and in a 5 track project: {"Track 5", "Track 2", "Track 1", "Track 4", "Track 3"}

    but i'm not giving up yet B-)>

  6. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Surprising. In all the tests I made, manually changing the tracks order, deleting some tracks and adding other ones, I didn't find a single case where the script didn't give the right result. Do we use the same version of GarageBand? Did you change the default preferences? (However I must confess that I actually know nothing about GarageBand.)

  7. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    i'm not sure why i'm seeing different results, we are using the same version, however I think, aside from the puzzle aspect, the question is moot.

    i'm going to have to poke at this more, but i came up with a routine to build a "correction table" automatically (thanks to your idea!), so the only work i have to do is adding new tracks to GB, naming them with a number, and running my program.

    i believe you got my project back to being possible again, thank you Pierre! ~~hang B-)>

  8. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    My pleasure, Hang. Many thanks for your feedback.