I've been trying to figure out a way to automate copying .mov's from a digital camera to a user's Movies dir in OS X for a less than computer savvy user, and thought I'd record what I've got.

Page on dates and Applescript
Page on using Applescript dialogs

My code right now...
set theDate to current date

set monthConstants to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with m from 1 to 12
if (month of theDate) = item m of monthConstants then set theMonthNum to m
end repeat
if theMonthNum < 10 then set theMonthNum to ("0" & theMonthNum)

set theDayNum to day of theDate
if theDayNum < 10 then set theDayNum to ("0" & theDayNum)

set strSuffixTime to "_" & year of theDate & theMonthNum & theDayNum & "_" & time of theDate

do shell script ("mkdir ~/Movies/" & strSuffixTime)
set destinationFolder to "X:Users:donna:Movies:" & strSuffixTime

set sourceFolder to choose folder with prompt "Choose the folder of movie files:"
set sourceFolder to sourceFolder as string

--set tempFolder to choose folder with prompt "spam"
--set tempFolder to tempFolder as string
--display dialog tempFolder

tell application "Finder"
duplicate (every file of folder sourceFolder whose name contains ".mov") to folder (destinationFolder)
display dialog "Done. Files should be in " & destinationFolder & "

Delete movie files from camera?" buttons ["OK", "Don't delete"]

if button returned of result is "OK" then
delete (every file of folder sourceFolder whose name contains ".mov")
display dialog "Files deleted."
else
display dialog "Files not deleted from camera."
end if

end tell


The above code is more a record of what I've learned than great, clean code, but there you go. Note to self.

Labels: