Complex search/replace help needed

Discussion in 'OS X Mavericks (10.9)' started by macstatic, Oct 30, 2015.

  1. macstatic macrumors 6502a

    Joined:
    Oct 21, 2005
    #1
    Here's the problem: I somehow managed to accidently change the creation dates of many image files, so even though they're from 2013 and 2014 they're now dated 23rd June 2015. Fortunately I have backup drives with their original dates. Since we're talking hundreds (perhaps thousands) of files here the challenge is to figure out how to avoid doing this manually, one file at a time.

    So far is to use the Finder's search function using the date and file criteria, so the affected files have all been identified and tagged. The files are all neatly organized inside folders/sub-folders, so is there a quick and simple way to have the unaffected copies replace the affected ones, all in their correct folders?
     
  2. Ebenezum macrumors 6502a

    Joined:
    Mar 31, 2015
    #2
    I haven't tested this but you might be able to do this with Automator.

    Be sure to have a backup before trying this!

    First pick "get Finder items" and choose correct tag. Then pick "Copy Finder items" and choose replace files option. Also choose folders where you want to copy the items. Save it as a software so you can use it again if necessary.
     
  3. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #3
    I've set up a small test setup to mimick my external hard drives before commiting to handling perhaps thousands of files by creating an "Error" and "OK" folder which both contains the exact same sub-folders/structure and images within. The only difference being the "Error" folder has its file-creation dates changed to something crazy.
    I've also used the OSX search function on the "Error" folder and tagged its image contents with a descriptive "wrong creation dates" tag as well as a color label to easily see if the offending files have been replaced. The only other thing I have to check is if the incorrectly dated images have been replaced with the exact same images (only with ocrrect creation dates of course).

    As for Automator I'm not sure I understand...
    I can't find a "Get Finder items" -there's only "Get selected Finder items" or "Get specified Finder items" and neither has the option for adding a tag. And when you say that I should choose folders where I want to copy the items to, do you mean specify every folder or just the main (root) folder?
    I thought struck me.... if I set up an OSX smart-search criteria (including the erronous creation date) on the "error" root-folder which will display all the offending files, then in a separate Finder window set up the exact same search criteria (but for the "OK" folder and without the creation date criteria); could I simply select everything shown in the "OK" window, then drag it over to what the smart-search criteria in the "Error" folder window is showing and OSX will take care of copying over each file to their correct folder locations -would that work?
     
  4. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #4
    Argh! :mad:
    I just tried it (dragging the "OK" files over to the "Error" files but the mouse pointer turned to a white "prohibited" symbol and wouldn't let me do it.
     
  5. Ebenezum macrumors 6502a

    Joined:
    Mar 31, 2015
    #5
    Sorry for misunderstanding, english isn't my first language and I was not certain how to translate Automator functions.

    Option 1: If you pick selected Finder items it should work since you can first select correct tag in Finder. Then choose root Folder and automator should be able to copy items correctly for you. I cannot quarantine this will work but I see no reason why it wouldn't.

    Option 2: Press record button in Automator and do the copying for test file, if it succeeds modify resulting Automator function to include all folders and files you want to change.

    Option 3: Use Finder instead of Automator, it will certainly work but it will likely be more work compared to other options.
     
  6. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #6
    I'm sorry -I can't figure this out :(
    I need a step by step guide or maybe there's a working solution out there which I can modify for my folders/paths?
     
  7. Ebenezum macrumors 6502a

    Joined:
    Mar 31, 2015
    #7
    Here a some links that may be helpful.

    OS X Automation explains how to use Automator and what you can do with it.
    Yourbusiness has an example on how to use Automator for deleting files, it isn't exactly what you need but it should work with minor modifications.
     
  8. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #8
    Thanks, I'll see if I can figure it out.

    I believe this is what I need to do, then automate the procedure using Automator:


    Preparation (locating and tagging the erronous files)
    1) In the Finder, open a window, navigate to the root folder of where the files with the wrong creation dates are located, then perform a search with the needed criteria to find those files. This is what I used (first of all searching for "." as I assumed that would search for any file with an extension):
    Screen Shot 2015-11-02 at 10.24.23.png

    Be sure to search within that root folder (named "Err" in my test-example) and save the smart-search with a descriptive name (e.g. "ERR creation dates").

    2) Since all the erronous creation-date images are now displayed all at once, tag them in the Finder (select all, right-click and click on "tags" in the pop-up menu. At the same time add a red color label.

    3) In the Finder, open up another new window, navigate to the root folder of where the correct creation-date files are located, then perform a smart search for the files with the correct creation dates using this search criteria:
    Screen Shot 2015-11-02 at 10.32.44.png

    Ensure searching is performed within the correct folder ("OK" in this example) and save the search as a smart-search with a descriptive name (e.g. "OK creation dates").

    4) As with the previous window, tag the OK files as well (e.g. "OK creation dates" and a green label)

    That's the easy part done... :)
    now that we've determined which files have the incorrect creation dates and which root folder contains the same files with the correct dates we need to figure out a way to actually replace them, so here's my analysis of that:


    File replacing (ultimately done automatically in some way)
    1) display ALL “error” files (wrong creation dates) in a Finder window root folder

    2) display ALL “OK” files (correct creation dates) in another Finder window root folder (same structure as with the error files)

    3) examine the entire file path of first “error” file

    4) locate same file on “OK” drive with the exact same path as above, but on different drive

    5) copy the “OK” file (correct creation date) over to equivalent “Error” folder, but first renaming the existing “error” file by adding “_error_creation_date” at the end of the filename,
    then adding an “OK creation date” tag to copied file as well as an additional “green” color label.
    This will ensure I can revert in case something goes wrong, and the replaced file will be clearly visible with its tag/label.

    6) repeat procedure for second file, then third, fourth etc.



    Does this seem correct? Have I missed anything?
     
  9. Ebenezum macrumors 6502a

    Joined:
    Mar 31, 2015
    #9
    It should work.

    To be on the safe side I would first test it on 1 file with Automator, then you can easily spot any potential errors and correct them before modifying all files.

    I hope it works without problems! :)
     
  10. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #10
    Thanks for all your help but I'm stuck :confused:
    Are there any specialized/specific Automator and/or Applescript related forums around?
     
  11. Ebenezum macrumors 6502a

    Joined:
    Mar 31, 2015
    #11
    You might want to try posting to Macrumors programming forum.

    Alternatively you can try Apple discussions, there is a forum dedicated to Automator and AppleScript.
     
  12. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #12
    Thanks for your suggestions.
    By the way, where are the Finder Service actions located? I found some at ~/Library/Services/ but those are apparently only a few of those available when I right-click on a file and select "Services". I also found some Services at /System/Library/Services/ and /Library/Services/ but there are more services installed than what I can see in any of those places, and I'd like to disable those I don't ever use.
     
  13. Ebenezum macrumors 6502a

    Joined:
    Mar 31, 2015
    #13
    Strange, those locations are were services are supposed to be installed.

    Etrecheck (diagnostic software) maybe able to show you any missing services. Alternatively if you remember name of the services you might be able to find them with EasyFind (fast way to find folders, files, etc. on Mac).
     

Share This Page