• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
itunes & text edit fun
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

itunes & text edit fun


  • Subject: itunes & text edit fun
  • From: "Patrick Collins" <email@hidden>
  • Date: Fri, 18 Mar 2005 23:06:55 -0800 (PST)
  • Organization: Collinator Studios

ok.. the story behind this script is as follows:

my mother found a website which contained over 1000 mp3s that she wanted..  so rather than having her click and download each one, i decided to help write a script that would go through the html code and find .mp3 and paste it into a text file with WGET infront of it, so then i could chmod it on the command line and give it to her, and now her computer is apparently downloading 1000 files right now as we speak...

the next problem that was found was that each of these files were missing info tags..  they were just named 0005.mp3 etc.. and had no info for artist, composer, album etc........

So then I wrote another script to go through the html and search for the fields between <td> amd /<td> which typically contained the atist, composer, album info...  Sometimes it did not (sometimes it was <td height=23>.. so i had to manually go through this file with find/replace and modify it so it was all consistent.  I ended up changing the </td> to </td] so that my script would never get confused for the > of <TD> and the > of </td>....

so..  I created another section of the script which then takes those items that were found in text edit, and stores them in the title, artist, composer, and album fields on the individual tracks of iTunes....................

So when i run this in script editor, the event log shows that everything works perfectly...  a small example of what I see is:

  (* ,  , <, t, d, >, M, o, u, n, t,  , H, e, r, m, o, n,  , C, o, n, f, e, r, e, n, c, e, <, /, t, d, ],
*)
    (*albumname Mount Hermon Conference*)
    (* ,  , <, t, d, >, R, a, y,  , C, .,  , S, t, e, d, m, a, n, <, /, t, d, ],
*)
    (*artistname Ray C. Stedman*)
    (*math increased 1*)
    (* ,  , <, t, d, >, B, e, w, a, r, e, <, /, t, d, ],
*)
    (*titlename Beware*)
    (*math increased 2*)
    (* ,  , <, t, d, >, V, a, r, i, o, u, s, <, /, t, d, ],
*)
    (*composername Various*)
    (*math increased 3*)
    (* ,  , <, t, d, >, M, o, u, n, t,  , H, e, r, m, o, n,  , C, o, n, f, e, r, e, n, c, e, <, /, t, d, ],


as you can see, it is successfully dietecting the appropriate fields and storing them in artistname,albumname,titlename, and composer name...

THEN........ it goes to the itunes part

and mind you I just created 31 one second mp3 files just to test this out--- and I get in the event log:

get selection
        {file track id 11670 of library playlist id 5757 of source id 34, file track id 11680 of library playlist id 5757 of source id 34, file track id 11678 of library playlist id 5757 of source id 34, file track id 11694 of library playlist id 5757 of source id 34, file track id 11690 of library playlist id 5757 of source id 34, file track id 11692 of library playlist id 5757 of source id 34, file track id 11696 of library playlist id 5757 of source id 34, file track id 11710 of library playlist id 5757 of source id 34, file track id 11714 of library playlist id 5757 of source id 34, file track id 11712 of library playlist id 5757 of source id 34, file track id 11716 of library playlist id 5757 of source id 34, file track id 11718 of library playlist id 5757 of source id 34, file track id 11724 of library playlist id 5757 of source id 34, file track id 11720 of library playlist id 5757 of source id 34, file track id 11722 of library playlist id 5757 of source id 34, file track id 11748 of library playlist id 5757 of source id 34, file track id 11746 of library playlist id 5757 of source id 34, file track id 11752 of library playlist id 5757 of source id 34, file track id 11750 of library playlist id 5757 of source id 34, file track id 11758 of library playlist id 5757 of source id 34, file track id 11754 of library playlist id 5757 of source id 34, file track id 11756 of library playlist id 5757 of source id 34, file track id 11760 of library playlist id 5757 of source id 34, file track id 11762 of library playlist id 5757 of source id 34, file track id 11768 of library playlist id 5757 of source id 34, file track id 11766 of library playlist id 5757 of source id 34, file track id 11764 of library playlist id 5757 of source id 34, file track id 11774 of library playlist id 5757 of source id 34, file track id 11770 of library playlist id 5757 of source id 34, file track id 11776 of library playlist id 5757 of source id 34, file track id 11772 of library playlist id 5757 of source id 34}
    count selection 31

................  And I am seeing how these file track id's are crazy and out of order..  Which I dont understand since I just created them all right there on the spot-- they all have the date of 10:30pm tonight......

anyway the result of my script is.. it looks like its working, the files are renaming before my eyes.. but then all of a sudden, one of the tracks jumps to a different place.. and things are going totally out of order.. and getting screwed up.........  And I tried sorting by different properties-- such as TIME, and Date Added.. since all files are 1 second and they all were created at 10:30 tonight.. I would not expect them to be moving, but they still jump around, and get out of order..  So...  Basically everything in the event log before itunes shows that it is all perfect, and in the correct order...  but once it gets to itunes it goes crazy......

So a question I have for all of you is..  Is there a better way I can accomplish this?  Right now I have iTunes working off of a selection (all 31 files that I wanted to rename I had to highlight)..  so I am wondering, is there a way to just have one file name selected, and then have applescript command it to move the selection down one by one until it reaches 31???  How would this be accomplished?  Once again I can't make much sense out of the dictionary as to how to accomplish this-- I guess one way might be to force a down-arrow key stroke???  Would that be the best way?  Thank you all for your guidance, kindness, help, and understanding.

-patrick

my script is as follows:


set donaldduck to false
set mickey to false
set speaknmath to 0
set artistname to {}
set titlename to {}
set composername to {}
set albumname to {}
set trackadvance to 0
set trackmodlist to {}
set tmpWord to ""
tell application "TextEdit"
    activate
    set allcharacters to every paragraph of document 1
    log allcharacters
    repeat with x in allcharacters
        if x contains "<td>" and x contains "</td]" and x does not contain "<td></td]" then
            set theCharacters to characters of x
            log theCharacters
            repeat with tmpChar in theCharacters
                set tmpcharstr to (tmpChar as string)
                if tmpcharstr = ">" and not donaldduck then
                    set tmpcharstr to ""
                    set donaldduck to true
                    set mickey to true
                else if tmpcharstr = "<" and donaldduck then
                    set donaldduck to false
                end if
                if donaldduck and not mickey then
                    set tmpWord to tmpWord & tmpcharstr
                end if
                set mickey to false
            end repeat
            set tmpWord to (tmpWord as string)
            if speaknmath = 0 then
                if tmpWord ≠ "" then
                    set the end of artistname to tmpWord
                    log "artistname " & tmpWord
                end if
            end if
            if speaknmath = 1 then
                
                if tmpWord ≠ "" then
                    set the end of titlename to tmpWord
                    log "titlename " & tmpWord
                end if
            end if
            if speaknmath = 2 then
                if tmpWord ≠ "" then
                    set the end of composername to tmpWord
                    log "composername " & tmpWord
                end if
            end if
            if speaknmath = 3 then
                if tmpWord ≠ "" then
                    set the end of albumname to tmpWord
                    log "albumname " & tmpWord
                end if
            end if
            if speaknmath < 3 then
                set speaknmath to speaknmath + 1
                log "math increased " & speaknmath
            else
                set speaknmath to 0
            end if
        end if
        set tmpWord to ""
    end repeat
    display dialog "About to rename tracks..."
    my itunesscript(titlename, albumname, artistname, composername)
end tell

display dialog "tracks have been renamed!" buttons {"ok"} default button 1

on itunesscript(titlename, albumname, artistname, composername)
    set trackadvance to 0
    tell application "iTunes"
        activate
        if selection is not {} then
            set sel to a reference to selection
            set number_of_tracks to count items of sel
            repeat with aTrack in sel
                set trackadvance to trackadvance + 1
                
                set name of aTrack to (item (trackadvance) of titlename as string)
                
                set artist of aTrack to (item (trackadvance) of artistname as string)
                
                set album of aTrack to (item (trackadvance) of albumname as string)
                
                set composer of aTrack to (item (trackadvance) of composername as string)
            end repeat
        end if
    end tell
end itunesscript
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: itunes & text edit fun
      • From: Neil Faiman <email@hidden>
  • Prev by Date: Setting all subfolder views to list
  • Next by Date: Re: Unicode Codepoints
  • Previous by thread: Re: Setting all subfolder views to list
  • Next by thread: Re: itunes & text edit fun
  • Index(es):
    • Date
    • Thread