Help with Sort by date on Parent folder contents

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Some movies that I have downloaded have a naming scheme similar to this:
(if the movie was The Usual Suspects):
tusa.avi - (this would be part1)
tusb.avi - (this would be part2)

I was thinking I could rename the files by their last modified date.
So I was thinking about trying to sort the contents of the parent directory by date and select the first item and then run rules on it, but I am having trouble. As I am not versed in applescript here is what I have so far. Any pointers or help would be appreciated.

Code: Select all
tell application "Finder"
   set posix_parent_dir to POSIX path of (container of (item theFile) as text)

   set allitems to sort (every item of posix_parent_dir) by creation date
   set a to item 1 of allitems

end tell
return {hazelSwitchFile:posix_parent_dir}
HerbDavisY2K
 
Posts: 7
Joined: Fri Dec 11, 2009 3:57 pm

Are you trying to change the target of the rule to that first item? If so, it seems you are setting posix_parent_dir (btw, it looks like you are copy/pasting this from the other example) to the file, sort, grab the first item, then return the original file to Hazel. You need to change that record in the return statement to be "a" instead of posix_parent_dir.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Here is what I have:

Movies
---The.Usual.Suspects
------tusa.avi
------tusb.avi

Im running the "go into subdirectories" rule on the "Movies" folder
Then I'm trying to come up with a rule to select one of the avi files

I thought of using modification date as a way to differentiate between the two avi files since typically the newest modification date will be the 2nd avi.

And yes, I was copy/pasting. As don't know applescript I'm just copy/pasting code I find on here and macsripter.

The code I posted doesn't run though :(
HerbDavisY2K
 
Posts: 7
Joined: Fri Dec 11, 2009 3:57 pm

I'm still not sure what you are trying to do ultimately and I get the sense using this script is not the way to do it. What do you want to do to the first file that you don't do to the second?
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Ultimately I want the files names "parent folder.cd#" (#=1 or 2)
HerbDavisY2K
 
Posts: 7
Joined: Fri Dec 11, 2009 3:57 pm

Well after searching and searching macscripter, I have come up with this:

I put this as an additional "do the following" for the rule "go into subfolders"

Code: Select all
set myFolder to theFile
set theParent to name of (info for theFile)
tell application "Finder"
   set AVISorted to sort (files of entire contents of myFolder whose name ends with ".avi") by modification date
   set mp4Sorted to sort (files of entire contents of myFolder whose name ends with ".mp4") by modification date
   
   set AVISortedR to reverse of AVISorted
   set MP4SortedR to reverse of mp4Sorted
   set CA to count AVISorted
   set CM to count mp4Sorted
   
   repeat with ka from 1 to CA
      if (count of AVISorted) is greater than 1 then
         set name of item ka of AVISortedR to theParent & ".cd" & ka & ".avi"
      else
         set name of item ka of AVISortedR to theParent & ".avi"
      end if
   end repeat
   
   repeat with km from 1 to CM
      if (count of mp4Sorted) is greater than 1 then
         set name of item km of MP4SortedR to theParent & ".cd" & km & ".mp4"
      else
         set name of item km of MP4SortedR to theParent & ".mp4"
      end if
   end repeat
end tell


It seems to work so far
HerbDavisY2K
 
Posts: 7
Joined: Fri Dec 11, 2009 3:57 pm


Return to Support

cron