Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 12-26-2010, 12:52 PM   #1
mdwittenberg
Prospect
 
Join Date: May 2010
Posts: 21
Modify Files According to List

Hello,

I've got a massive treasury of old family film footage that I'm importing into iMovie '11. When I import the files, it classifies the movies as the current year rather than the date when they were actually created. I've discovered I can change the date displayed in iMovie by using the "touch" command in terminal to alter iMovies files in "~/Movies/iMovie Events". Furthermore, I've discovered this lovely script which makes it quite easy to modify individual files.

However, I've got 300+ files and don't want do that to each one. I noticed that iMovie preserves name for these files. Therefore, I have two directories with the same file names:
1) My original files with the correct "date created" as ".mpg" files located in "~/Movies/SonyCam/Vacations"
2) iMovie's imported footage with today's date as ".m4v" files located in "~/Movies/iMovie Events/Vacations"

My goal is have an Applescript that will take the "date created" from each ".mpg" and apply it to the respective ".m4v". Is this possible? If so, where do I start?

Thanks,
Mitch
mdwittenberg is offline   Reply With Quote
Old 12-26-2010, 01:42 PM   #2
renaultssoftware
MVP
 
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
Likely you can:
A) get the file name and both associated files
B) get the one correct date
C) set the other's modification date (can't create new creation dates)

Pretty easy in vanilla AS. Being away from a Mac, I can't help right now.
__________________
Get Icon Creator and support me.
renaultssoftware is offline   Reply With Quote
Old 12-26-2010, 07:46 PM   #3
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,819
A Better Finder Attributes should do the trick, and if all of your footage has already been imported, I think you'll be able to make all of the desired modifications during the software trial period.
NaOH is offline   Reply With Quote
Old 12-26-2010, 08:27 PM   #4
mdwittenberg
Prospect
 
Join Date: May 2010
Posts: 21
@renaultssoftware I'm glad to hear that this is possible. Sadly, such scripting is beyond my capabilities

@NaOH While that software is a very polished solution, I don't see what additional functionality it delivers over my droplet. My videos span twenty years and I hope to avoid modifying each one individually. And while the "instant droplet" is nice, I'd still have to make a new droplet every four or five clips.
mdwittenberg is offline   Reply With Quote
Old 12-27-2010, 07:48 AM   #5
fracai
MVP
 
Join Date: May 2004
Posts: 2,089
I can put something together for you, I've done things very similar in the past.

First though, do you need the creation date to be set? Or just the modification date?
Same question for where to get the date (creation or modification). These will have an impact on what tools I use in the shell script.
fracai is offline   Reply With Quote
Old 12-27-2010, 11:58 AM   #6
mdwittenberg
Prospect
 
Join Date: May 2010
Posts: 21
@fracai Thank you very much! I believe I want to grab and set the creation date. Previously, I used this script which set the correct metric to fool iMovie – so whatever that script did is sufficient.

Last edited by mdwittenberg; 12-27-2010 at 12:01 PM.
mdwittenberg is offline   Reply With Quote
Old 12-27-2010, 12:27 PM   #7
fracai
MVP
 
Join Date: May 2004
Posts: 2,089
OK, that script is actually setting the access and modification dates. I'll give you a script which does the same and if it doesn't work I can update it to set the creation date. I'd like to avoid setting the creation date because that requires that you have the developer tools (GetFileInfo and SetFile).

Give me just a few minutes to test it out.
fracai is offline   Reply With Quote
Old 12-27-2010, 12:56 PM   #8
fracai
MVP
 
Join Date: May 2004
Posts: 2,089
Give this a shot:
Code:
#!/bin/sh

SOURCE_PATH=~/"Movies/SonyCam/Vacations"
UPDATE_PATH=~/"Movies/iMovie Events/Vacations"

SOURCE_EXT="mpg"
UPDATE_EXT="m4v"

for FILE in "$SOURCE_PATH"/*."$SOURCE_EXT" ; do
    BASE=$(basename "$FILE" ."$SOURCE_EXT")
    
    if [[ -f "$UPDATE_PATH"/"$BASE"."$UPDATE_EXT" ]];
    then
        echo "$FILE"
        DATE=$(stat -t %Y%m%d%H%M.%S -f %Sm "$FILE")
        touch -t "$DATE" "$UPDATE_PATH"/"$BASE"."$UPDATE_EXT"
    fi
done
Save it as "copy-dates.sh", edit the paths or extensions if you need to, make it executable with "chmod +x copy-dates.sh", and run it with "./copy-dates.sh"

Let me know if you have any problems or need the creation date set (I'm guessing that if the other script worked you'll be fine).

It basically operates on each file in the source directory and if a corresponding file is found in the iMovie directory it copies over the access and modification dates.
fracai is offline   Reply With Quote
Old 12-28-2010, 01:14 PM   #9
mdwittenberg
Prospect
 
Join Date: May 2010
Posts: 21
Sadly, that script did not work for me. I made it excitable in terminal, but it returned the shell very quickly when I ran it and didn't change the files.

I must admit that I fibbed in my first post for simplicity's sake (thinking that I could change the paths myself afterwards). The original files are actually located in an external drive "M and M" and the converted files aren't quite in iMovie yet. Furthermore I changed my mind and am converting to "mov" instead of "m4v". Here's what I modified:
Code:
...
SOURCE_PATH="/Volumes/M and M/Conversion Puragtory/Sony/07.04.15 Florida Vacation"
UPDATE_PATH="/Users/Projects/Movies/Ready for iMovie/Florida Vacation"

SOURCE_EXT="mpg"
UPDATE_EXT="mov"
...
Did I not put the file path in the correct format or something?
mdwittenberg is offline   Reply With Quote
Old 12-28-2010, 01:51 PM   #10
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,442
Add in a line:
echo "processing $FILE"
right after the 'for' statement. Then you can see what files are being processed.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 12-28-2010, 02:38 PM   #11
mdwittenberg
Prospect
 
Join Date: May 2010
Posts: 21
@hayne: Followed you suggestion and was returned
Code:
processing /Volumes/M and M/Conversion Puragtory/Sony/07.04.15 Florida Vacation/*.mpg
mdwittenberg is offline   Reply With Quote
Old 12-28-2010, 02:42 PM   #12
fracai
MVP
 
Join Date: May 2004
Posts: 2,089
That indicates that it's not actually finding any files to process. Are you sure you have the paths correct? Try the following command, do you see all your movies listed? Your UPDATE_PATH also looks iffy. Do you really have a user called "Projects"?

Code:
ls -la "/Volumes/M and M/Conversion Puragtory/Sony/07.04.15 Florida Vacation"/*.mpg
fracai is offline   Reply With Quote
Old 12-28-2010, 02:55 PM   #13
mdwittenberg
Prospect
 
Join Date: May 2010
Posts: 21
@fracai Ah! Thanks for the troubleshooting "ls -la" command. I figured out that my files' extensions are capitalized ("MPG") and the script was looking for lower case "mpg". Once I fixed that in the script it worked perfectly.
mdwittenberg is offline   Reply With Quote
Old 12-28-2010, 11:32 PM   #14
fracai
MVP
 
Join Date: May 2004
Posts: 2,089
:-)

I'm glad it worked and am happy to have helped.
fracai is offline   Reply With Quote
Old 12-28-2010, 11:53 PM   #15
mdwittenberg
Prospect
 
Join Date: May 2010
Posts: 21
You're the bomb fracai

Now I may be asking for too much, but is it possible to squeeze this into applescript/automator? My dream would be to have this in a foolproof AS or Automator action where the user picks the source folder, destination folder, and then the computer figures out the extension and does the time modification. These are my parents' videos and I'd prefer if they could manage future imports themselves.

ps I've found you can have multiple shell variables in automator.

Last edited by mdwittenberg; 12-28-2010 at 11:55 PM.
mdwittenberg is offline   Reply With Quote
Old 12-29-2010, 08:56 AM   #16
fracai
MVP
 
Join Date: May 2004
Posts: 2,089
I'm not much of an AppleScripter or Automator...er, but it'd certainly be possible to convert this. I think AS even has the capability for getting and setting modification times without going out to the shell.

The Hint you linked to, and the comments, probably have all you'd need to select source and update folders and then use the general pattern of my script to perform the update.

But, again, it's not my expertise.
fracai is offline   Reply With Quote
Reply

Tags
imovie 11

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:21 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.