I’ve been struggling with this one for some time and can’t find a suitable script on Doug’s AppleScripts for iTunes nor can I quite figure out lists from other posts on this board.
What I would like to do is run a script that prompts for the user to choose a name (with the possibility to expand should the need arise) from a list and then tag all of the tracks selected as that person’s music.
This script is written for me and my girlfriend so that we can share a master library and still have our music tagged according to our tastes. This is also set up to allow for the possibility that both of us like the same music. However, I also wanted the script to have the option of de-tagging a track. In other words, if it is first tagged as ‘His’ and discovered that is a mistake, running the script again should remove the ‘His’ and replace it with ‘Hers’ (or whatever is selected as the replacement) all the while maintaining any other information that happens to be in the tag.
The problem is in eliminating the current owner and replacing them when there are already multiple owners assigned.
Have I over-complicated things? Is there a way to clean up my script and make it work? Any help on the handling of lists would be GREATLY appreciated!
fs
p.s. Some variables in here don’t do anything because I got too frustrated after I put them in but before I did anything with them.
Well, with such long scripts, I often have a harder time going through to “fix” them than I do simpy re-writing them.
Keep in mind that this script will only work with 2 users (“his music” & "her music). You could add others, but you’ll need to give them a “cleanedList” so you don’t erase a users and then add it right back. It tries to deal with spaces and other info that may be present in the “Groupings” tag, (which is a lot of the reason it’s so long) but it may leave extra spaces and stuff if you end up with a “Groupings” tag that looks like “Test •his music Testagain •her music why not”. It’ll still get rid of the tags, but might leave two spaces between the remaining words (e.g., “Test Testagain why not”) But if you don’t use “Groupings” for anything else then you shouldn’t have any problems.
Thank you very much for your script. I appreciate the effort you put into it, however, I already have a hard-coded script that handles the addition and removal of the two of us.
This is actually my third attempt and, as an exercise in building my understanding of lists and dynamic variables, I wanted it to be as soft-coded (Is that even a real phrase) as possible.
Out of curiosity, how does the line ‘if database ID of eachSong is…’ work? This may be the key to my problem. If not, and if anyone else has suggestions on the (from my viewpoint) complex manipulation of lists, I would be very eager to learn more.
Again, jakacmar, thank you very much for your script. I’ll add it to my list of reference files and attempt to learn as much as I possibly can from your approach to my problem.
Ha ha. That’s what I get for not reading your first post as thoroughly as I should’ve. I’ve been doing that more and more recently. Oh well, good practice at the very least :lol:
The database ID is just a property of every track in your iTunes library. It’s unique to every single song so I thought it would be a good way to keep track of what was going on with what.
As far as “soft-coding” the script. The difficulty for me was that I needed to create a list for each user in order to keep track of things. I’ve got a (possible) work around in mind, I think I can just tag each entry in the list with a user name and then parse the list first for user names, and then for database IDs. I think it’ll even be a lot shorter. I’ll give it a look sometime later today and see if I can get something done.
Done! Ok, well, I doubt it’s any shorter, but I’ve added a few features. Since the list isn’t hard-coded, I’ve added a dialog box whenever the script is run which tells you what users are currently set up and allows you to change the users. This is (of course) fairly easily disable, though you might need to disable a few other things too (it’s not THAT clean). Anyway, if you change user names, and are using the same one as before, it will continue to work with old tags, but just in case, when you change users, I’ve provided a dialog to let you clear the onwership of either the selection or the entire iTunes Library. Clearing the entire Library takes a little while, but that’s to be expected.
I’ve tried to put it through it’s paces and test everything, but there’s always a possibility that it could error somewhere I missed in testing. If others could do the same and report any bugs you find (or that you found none) I’ll try to make any necessary fixes and get this over to Doug’s in the next day or so.
And of course, if you want to force the script to clear it’s list of users, etc. (the script not iTunes) you need to open it in script editor and resave it or add a space somewhere, delete it, and then resave it.
Sweet, sassy Siva! That is one fantastic script you’ve got there. I particularly enjoy the ‘Add New Users’ section. Here I was, all ready to leave my app accessible so the code could be altered for new users and you found a savvyer way. …I always wanted to figure out how to save preferences. It’s the Properties line, isn’t it?
Couple of gotcha’s from my tests. First (and this isn’t your fault, it’s AS’s), the List screen isn’t big enough to accomodate that many characters so it’s just a matter of re-wording that screen to get all the info in there.
I understand your wanting the person to select their name before it’s obliterated, and I can admire that point of view. It’s different from mine which says if a new name is picked, it writes over the old. Quite frankly, I can’t decide which I like better. Which brings me to my second Gotcha!
I tried to come up with a sensible way to explain the second Gotcha, but it just didn’t make sense (and was likely to never occur as a scenario), so I take that one back. I still think the changing of users should work …different, but for the time being, I consider the script perfect!
I always wanted to write something good enough to post to Doug’s and share with the world, and I felt it could have been this, but I just couldn’t wrap my head around the damn thing. In retrospect, had I altered my approach to name replacement and addition to match yours, it probably would have been a lot easier. In other words, thank you so much for your help. You can bet I’m going to be studying this bad-boy until I’ve gleaned as much information as my budding mad skillz can handle.
I noticed a problem in your new version of the script, so I took care of it. The script was deleting old comments before tagging them as belonging to someone else, so I just deleted the line that routs it to cleanTags and altered one variable in the addTags if-then segment.
I also tweaked the method of naming the users so that when a user puts their name in (ex. Jimbo), it tags the track as • Jimbo’s Music. This was just for my own sake. For anyone who doesn’t want that (and just wants to copy-paste and not have to rewrite script) just copy the sub-routine gatherUsers from jakacmar’s above post and paste it over my own version of the same sub-routine.
I’m confused, in your last post, you said you preferred that “if a new name is picked, it writes over the old”, but then you edited the script to add names instead of writing over them. Oh well. Glad it’s doing the job.
Thanks again for schooling me with your script. It’s been very helpful.
The problem I fixed occurred when a name was added for the very first time. It was eliminating unrelated text from the ‘grouping’ field before tagging it with the music owner’s name.
ex: ‘• Borrowed from Kearny’ when tagged as belonging to Jimbo became ‘• Jimbo’s Music’ instead of the preferred ‘• Borrowed from Kearney • Jimbo’s music’
Got ya. The only problem I can see arising is, if you accidentally try to tag a song twice for the same person, it will tag it twice, but that’s not a big deal really since the point is just to have the name in groupings I’m assuming, not necessarily how many times it’s there.
I’d assume most people would want to make some changes to the script to get exactly what they want, and it looks like you were able to do just that.