Loading ...
Sorry, an error occurred while loading the content.

Adding file creation date to iTunes podcast track name

Expand Messages
  • jamesehrler
    To be able to order some of my podcasts by date on my iPhone smart playlists, I created a simple macro. When launched in iTunes with a selected song
    Message 1 of 8 , Mar 1, 2012
    View Source
    • 0 Attachment
      To be able to order some of my podcasts by date on my iPhone smart playlists, I created a simple macro. When launched in iTunes with a selected "song" highlighted there it:

      1. goes to the selected song in the Finder via iTunes menu item "Show in Finder"
      2. uses A Better Finder Rename service to prepend the file creation date to the song name
      3. returns to iTunes
      4. invokes an Doug's AppleScript "Filenames to Song Names" that, surprise, changes the filename to the song name

      I am having some trouble with pausing the script to wait until the Finder is ready to use the service. I tried waiting until the Finder was front app but it sometimes just sat there waiting and waiting. Have just used time for now.

      Then I realized that I don't really need to go to the Finder and use A Better Finder Rename as I should be able to change the filename right from in iTunes with KM.

      Unfortunately the text tokens for iTunes don't include File Creation Date so I'm a bit stumped. It probably requires AppleScript Fu but my fu is weak.
    • Christopher Stone
      ... ______________________________________________________________________ Hey James, Yes, you were doing it the hard way. :) This is not complete, because it
      Message 2 of 8 , Mar 1, 2012
      View Source
      • 0 Attachment
        On Mar 01, 2012, at 14:23, jamesehrler wrote:
        To be able to order some of my podcasts by date on my iPhone smart playlists, I created a simple macro.  When launched in iTunes with a selected "song" highlighted there it:
        ______________________________________________________________________

        Hey James,

        Yes, you were doing it the hard way.  :)

        This is not complete, because it does not change the name of the file.  It is therefore non-destructive at this moment and safe for you to test.

        ------------------------------------------------------------------------------------------------
        try


        tell application "iTunes"
        set theSelectedTrack to item 1 of (get selection)
        set selectedTrackAlias to location of theSelectedTrack
        end tell
        set fileInfo to info for selectedTrackAlias
        set fileName to name of fileInfo
        set fileCreationDate to creation date of fileInfo
        set fileCreationDate to short date string of fileCreationDate
        set newName to fileCreationDate & " " & fileName
        set newName to do shell script "sed 's|/|-|g' <<< " & quoted form of newName


        on error eMsg number eNum
        set {c, s} to {return, "------------------------------------------"}
        set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
        beep
        display dialog e
        end try
        ------------------------------------------------------------------------------------------------

        Select a track in iTunes and run the script in the Applescript Editor to see what the new name looks like.

        If this is close tell me more specifically what you want, and I'll give you a completed version.

        --
        Best Regards,
        Chris

      • James R. Ehrler
        ... Dang, you are good! Works *so* much faster than my kludge. Three things. First, I would like the date form to be YY_MM_DD. Second, I can follow the
        Message 3 of 8 , Mar 2, 2012
        View Source
        • 0 Attachment
          ------------ --------- --------- --------- --------- --------- -
          try

          tell application "iTunes"
          set theSelectedTrack to item 1 of (get selection)
          set selectedTrackAlias to location of theSelectedTrack
          end tell
          set fileInfo to info for selectedTrackAlias
          set fileName to name of fileInfo
          set fileCreationDate to creation date of fileInfo
          set fileCreationDate to short date string of fileCreationDate
          set newName to fileCreationDate & " " & fileName
          set newName to do shell script "sed 's|/|-|g' <<< " & quoted form of newName

          on error eMsg number eNum
          set {c, s} to {return, "----------- --------- --------- --------- ----"}
          set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
          beep
          display dialog e
          end try
          ------------ --------- --------- --------- --------- --------- -

          Select a track in iTunes and run the script in the Applescript Editor to see what the new name looks like.

          If this is close tell me more specifically what you want, and I'll give you a completed version.

          --
          Best Regards,
          Chris

          Dang, you are good!  Works *so* much faster than my kludge.

          Three things.  First, I would like the date form to be YY_MM_DD.  Second, I can follow the AppleScript (I'm trying to learn, really) but don't know what the shell script line does.  Third, this seems to only work when one file is selected.  I suspect it needs a repeat.

          Thanks so much.  

          Regards,

          James R. Ehrler



        • Christopher Stone
          Hey James, ... I ve just been doing this for a few years, but thanks. :) ... Okay. That s easy to do. ... It is just changing the slash character in the date
          Message 4 of 8 , Mar 2, 2012
          View Source
          • 0 Attachment
            Hey James,

            On Mar 02, 2012, at 06:47, James R. Ehrler wrote:
            Dang, you are good!  Works *so* much faster than my kludge.

            I've just been doing this for a few years, but thanks.  :)

            Three things.  First, I would like the date form to be YY_MM_DD.

            Okay.  That's easy to do.

            Second, I can follow the AppleScript (I'm trying to learn, really) but don't know what the shell script line does.

            It is just changing the slash character in the date to a hyphen.

            The new Perl-based shell script also uses the underscore and it changes the format to yy_mm_dd.

            It's just a regular expression based find/replace.

            Third, this seems to only work when one file is selected.

            That's because you didn't say you wanted to operate on multiple items.  ;-)

            I suspect it needs a repeat.

            We'll see; probably.  I wanted to look at Doug's script and see if he was doing anything interesting, but it's pretty meat and potatoes.

            Okay try this script and see if it produces the format of file name you want.  If it does then we'll go about making it work with multiple items and actually change the names of the files in the Finder.

            --
            Best Regards,
            Chris

            ----------------------------------------------------------
            try


            tell application "iTunes"
            set theSelectedTrack to item 1 of (get selection)
            set selectedTrackAlias to location of theSelectedTrack
            set trackName to name of theSelectedTrack
            end tell
            set fileInfo to info for selectedTrackAlias
            set fileName to name of fileInfo
            set fileCreationDate to creation date of fileInfo
            set fileCreationDate to short date string of fileCreationDate
            set fileCreationDate to do shell script "perl -0777 -ne 's|^(\\d{2})/(\\d{2})/(\\d{2})(\\d{2}$)|\\4_\\1_\\2|g; print' <<< " & quoted form of fileCreationDate
            set newName to fileCreationDate & " " & trackName


            on error eMsg number eNum
            set {c, s} to {return, "------------------------------------------"}
            set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
            beep
            display dialog e
            end try
            ----------------------------------------------------------

          • jamesehrler
            ... Hmmm. Ending up with this 3/2/12 Forecast: Dreier, Then Snowe rather than 12_03_02 Forecast: Dreier, Then Snowe . Earlier I created and posted here a
            Message 5 of 8 , Mar 2, 2012
            View Source
            • 0 Attachment
              --- In keyboard_maestro@yahoogroups.com, Christopher Stone <listmeister@...> wrote:
              >
              > Hey James,
              >
              > On Mar 02, 2012, at 06:47, James R. Ehrler wrote:
              > > Dang, you are good! Works *so* much faster than my kludge.
              >
              > I've just been doing this for a few years, but thanks. :)
              >
              > > Three things. First, I would like the date form to be YY_MM_DD.
              >
              > Okay. That's easy to do.
              >
              > > Second, I can follow the AppleScript (I'm trying to learn, really) but don't know what the shell script line does.
              >
              > It is just changing the slash character in the date to a hyphen.
              >
              > The new Perl-based shell script also uses the underscore and it changes the format to yy_mm_dd.
              >
              > It's just a regular expression based find/replace.
              >
              > > Third, this seems to only work when one file is selected.
              >
              > That's because you didn't say you wanted to operate on multiple items. ;-)
              >
              > > I suspect it needs a repeat.
              >
              > We'll see; probably. I wanted to look at Doug's script and see if he was doing anything interesting, but it's pretty meat and potatoes.
              >
              > Okay try this script and see if it produces the format of file name you want. If it does then we'll go about making it work with multiple items and actually change the names of the files in the Finder.
              >
              > --
              > Best Regards,
              > Chris
              >
              > ----------------------------------------------------------
              > try
              >
              > tell application "iTunes"
              > set theSelectedTrack to item 1 of (get selection)
              > set selectedTrackAlias to location of theSelectedTrack
              > set trackName to name of theSelectedTrack
              > end tell
              > set fileInfo to info for selectedTrackAlias
              > set fileName to name of fileInfo
              > set fileCreationDate to creation date of fileInfo
              > set fileCreationDate to short date string of fileCreationDate
              > set fileCreationDate to do shell script "perl -0777 -ne 's|^(\\d{2})/(\\d{2})/(\\d{2})(\\d{2}$)|\\4_\\1_\\2|g; print' <<< " & quoted form of fileCreationDate
              > set newName to fileCreationDate & " " & trackName
              >
              > on error eMsg number eNum
              > set {c, s} to {return, "------------------------------------------"}
              > set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
              > beep
              > display dialog e
              > end try
              > ----------------------------------------------------------
              >

              Hmmm. Ending up with this "3/2/12 Forecast: Dreier, Then Snowe" rather than "12_03_02 Forecast: Dreier, Then Snowe".

              Earlier I created and posted here a regex search and replace that converts dates to include leading zeroes. Would that be helpful?
            • Christopher Stone
              ... ______________________________________________________________________ Hey James, Okay. I have my system set to automatically provide leading zeros, but
              Message 6 of 8 , Mar 2, 2012
              View Source
              • 0 Attachment
                On Mar 02, 2012, at 21:30, jamesehrler wrote:
                > Hmmm. Ending up with this "3/2/12 Forecast: Dreier, Then Snowe" rather than "12_03_02 Forecast: Dreier, Then Snowe".
                >
                > Earlier I created and posted here a regex search and replace that converts dates to include leading zeroes. Would that be helpful?
                ______________________________________________________________________

                Hey James,

                Okay. I have my system set to automatically provide leading zeros, but you evidently do not.

                I'll fix it, so it doesn't matter - but probably not until tomorrow.

                --
                Best Regards,
                Chris
              • Christopher Stone
                ... ______________________________________________________________________ Hey James, Okay. Try this. If it gives the name format you want we ll go from
                Message 7 of 8 , Mar 2, 2012
                View Source
                • 0 Attachment
                  On Mar 02, 2012, at 21:30, jamesehrler wrote:
                  Hmmm.  Ending up with this "3/2/12 Forecast: Dreier, Then Snowe" rather than "12_03_02 Forecast: Dreier, Then Snowe".
                  ______________________________________________________________________

                  Hey James,

                  Okay.  Try this.  If it gives the name format you want we'll go from there.

                  --
                  Best Regards,
                  Chris

                  ----------------------------------------------------------
                  try


                  tell application "iTunes"
                  set theSelectedTrack to item 1 of (get selection)
                  set selectedTrackAlias to location of theSelectedTrack
                  set trackName to name of theSelectedTrack
                  end tell
                  set fileCreationDate to creation date of (info for selectedTrackAlias)
                  tell fileCreationDate
                  set fileCreationDate to (text 3 thru -1 of (its year as text)) & ¬
                  "_" & characters -2 thru -1 of ("0" & (its month as number)) & ¬
                  "_" & characters -2 thru -1 of ("0" & (its day))
                  end tell
                  set newName to fileCreationDate & " " & trackName


                  on error eMsg number eNum
                  set {c, s} to {return, "------------------------------------------"}
                  set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
                  beep
                  display dialog e
                  end try
                  ----------------------------------------------------------

                • jamesehrler
                  ... Perfect! 12_03_02 Forecast: Dreier, Then Snowe
                  Message 8 of 8 , Mar 3, 2012
                  View Source
                  • 0 Attachment
                    --- In keyboard_maestro@yahoogroups.com, Christopher Stone <listmeister@...> wrote:
                    >
                    > On Mar 02, 2012, at 21:30, jamesehrler wrote:
                    > > Hmmm. Ending up with this "3/2/12 Forecast: Dreier, Then Snowe" rather than "12_03_02 Forecast: Dreier, Then Snowe".
                    >
                    > ______________________________________________________________________
                    >
                    > Hey James,
                    >
                    > Okay. Try this. If it gives the name format you want we'll go from there.
                    >
                    > --
                    > Best Regards,
                    > Chris
                    >
                    > ----------------------------------------------------------
                    > try
                    >
                    > tell application "iTunes"
                    > set theSelectedTrack to item 1 of (get selection)
                    > set selectedTrackAlias to location of theSelectedTrack
                    > set trackName to name of theSelectedTrack
                    > end tell
                    > set fileCreationDate to creation date of (info for selectedTrackAlias)
                    > tell fileCreationDate
                    > set fileCreationDate to (text 3 thru -1 of (its year as text)) & ¬
                    > "_" & characters -2 thru -1 of ("0" & (its month as number)) & ¬
                    > "_" & characters -2 thru -1 of ("0" & (its day))
                    > end tell
                    > set newName to fileCreationDate & " " & trackName
                    >
                    > on error eMsg number eNum
                    > set {c, s} to {return, "------------------------------------------"}
                    > set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
                    > beep
                    > display dialog e
                    > end try
                    > ----------------------------------------------------------
                    >

                    Perfect! "12_03_02 Forecast: Dreier, Then Snowe"
                  Your message has been successfully submitted and would be delivered to recipients shortly.