osx - AppleScript: match and delete files in folder -
my photo camera allows save pictures in raw , jpg in parallel. find convenient because on mac can browse jpgs , delete "bad" ones. besides, keep raw files of "good" jpgs in case need deep editing.
i write applescript deletes "bad" raws (raw files don't have corresponding jpg anymore). files in same directory.
this outline (far away correct syntax!):
tell application "finder" set source_folder choose folder prompt "please select directory." clearfiles(source_folder) end tell on clearfiles(source_folder) set theitems "" tell application "system events" set theitems name of every disk item of source_folder end tell repeat thefile in theitems if extension of thefile "raw" , exists name of thefile & ".jpg" tell finder delete (name of thefile & ".raw") in source_folder , tell end if end tell end clearfiles
try this
set source_folder choose folder prompt "please select directory." tell application "finder" set rawfiles every file of source_folder name extension "raw" repeat afile in rawfiles set basename text 1 thru -5 of (get name of afile) set jpgfile basename & ".jpg" if not (exists file jpgfile of source_folder) delete afile end repeat end tell
Comments
Post a Comment