Write a script to do this?

Discussion in 'Mac Programming' started by Inconsequential, Nov 12, 2007.

  1. macrumors 68000

    Joined:
    Sep 12, 2007
    #1
    Ok I have a gallery with 4000ish images in (12,000 if you count 3 versions of each).

    Now 95% of these images either are wrong JPEG quality, no watermark, wrong watermark or no auto levels etc on them.

    Now I need a script/workflow that can do this:

    EG. Images that need to be replaced:
    /foldera/IMG_1001-01.jpg
    /foldera/IMG_1005-01.jpg
    /foldera/normal_IMG_1001-01.jpg
    /foldera/normal_IMG_1005-01.jpg
    /foldera/thumb_IMG_1001-01.jpg
    /foldera/thumb_IMG_1005-01.jpg

    Originals of foldera are in folderb

    /folderb/IMG_1001.CR2
    /folderb/IMG_1002.CR2
    /folderb/IMG_1003.CR2
    /folderb/IMG_1004.CR2
    /folderb/IMG_1005.CR2


    So the script has to use "IMG_1001-01.jpg", then search for its original "IMG_1001" in folderb, then it has to run a workflow that I already have that works perfectly to replace the "IMG_1001-01.jpg", "normal_IMG_1001-01.jpg" and "thumb_IMG_1001-01.jpg" in foldera.

    I can't just run my image edit script on ALL the images because only 50% of the originals have been uploaded, and I really don't want to have to spend weeks doing it all manually by deleting the ones I don't want.

    Recording my actions doesn't work :(

    Any ideas or am I destined to manual labour to replace them all?

    Cheers :)

    Edit: OS X 10.5 Panther on a MBP 2.4 so X11 can be installed or whatever you lot think is best :)
     
  2. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #2
    Seems doable in a Ruby script. If you could better (exactly) define the process, I could probably get to this over the weekend. (Unless someone jumps on this before I do - which is fine ;) )

    Todd
     
  3. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #3
    Yea if you got MSN I should be able to answer your questions more easily :)
     
  4. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #4
    I have MSN, but it's on the Window's machine, so I would have to get out of my chair, go to the other side of the desk, and establish myself there.

    I have iChat too (preferred) - see my profile. However, I would prefer this format.

    I'll start by putting down some psuedo code and you can tell me where it needs changing. My intent is not to make this general purpose, but to run on your machine with your paths, your folder names, your rules, etc.

    Code:
    image_folder = "~/Documents/foldera/" 
    source_folder = "~/Documents/folderb/" ; 
    
    for each file in <image_folder> { 
    
    name = file without the extension 
    
    call your-process <source_folder + name + ".jpg"> 
    
    }  
    
    Seems simple enough.

    Do I need to delete the existing file in foldera?
    Do I need to delete the corresponding files in the thumbnail and normal folders?
    What other parms need to be passed to your process?
    How to call your process?
    Could your process error-out?

    What else?

    If I get a shell working, would you be able to modify it for your path names or making the process call?

    Todd
     
  5. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #5
    I should be if its just a case of editing /foldera/ to /folderb/ etc :)

    As for your questions:

    1 + 2: No, you don't need to delete it. This is my current workflow:

    http://www.thunder-keep.co.uk/site/automator1.jpg

    It will be updated to do thumbnails as well, but it gives you the idea of what each image has to go through.

    The original has to be saved into foldera using that process, although it probably doesn't matter as its easy enough to just copy them across and overwrite them.

    So I guess the script just has to make up a file list, copy the images into the "Get specified folder items" and then commence the workflow.

    How to call my process? :confused: As in how to start it?

    I don't think this script could error out really its that simple, but maybe some notification saying that no images found or no source images found...

    My coding skill is limited to find and replace :p

    Cheers :)

    Edit: I don't have a iChat account anymore :( I never did get a .mac account..

    Edit 2: Maybe I do LOL added :)
     
  6. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #6
    OK, now I'm confused. Perhaps you should't have shown me your work flow!

    Can you be succinct and tell me exactly what you want the script to do?

    Todd
     
  7. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #7
    Ok.

    Ill use images to help :p

    [​IMG]

    Ok.

    Steps:
    1. The script has to grab all the images that have "IMG_XXXX-01.jpg" in "3rdfeb2007".
    2. then it has to select just "IMG_XXXX"
    3. it then has to search for the original in the second folder "G-BBDG - 3rd February 2007".
    4. Adds this original file into the "Get specified folder items".
    5. Runs the workflow.

    [Thats the main bit the next bit isn't *that* important]

    6. Once all the images that were found in step 1 and the originals found, it has to set the OUTPUT folder in the "Render -> Save for Web" part of the workflow to the source folder (in this case 3rdfeb2007).


    That more easy to understand? :)
     
  8. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #8
    I've never used Automator. After browsing through it, I think I can prefix your "Get Specified Finder Items" with "Run Shell Script" and pass the names and paths as text.

    Can anyone confirm this is the proper approach?

    Todd
     

    Attached Files:

  9. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #9
    Could you make a simple script to test it?

    Probably possible :D
     
  10. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #10
    Ran out of time - didn't get to this. Sorry.

    Todd
     
  11. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #11
    Ah ok, do you have time in the near future or shall I ask for someone else? :)

    Cheers CR
     
  12. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #12
    Actually, it might be better to find someone else. Too much to do this time of year. Sorry, I just don't have free time to devote to this.

    Todd
     
  13. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #13
    Ah ok.


    *calls out to MacRumors programming people*

    Who wants a bash at trying to do this???
    :D:D:D:D

    Cheers CR
     
  14. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #14
    Anyone??

    Come on, someone must fancy this task ;):p
     
  15. macrumors regular

    Joined:
    Oct 13, 2005
    #15
    Bizarrely, I actually have a little free time coming up this weekend, if you can wait that long. Although I'm a ruby fan like Todd, it seems to me that this is all doable in Automator. Oh, one question: Are you running Tiger or Leopard?
     
  16. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #16
    Leopard.

    And Weekend is cool.

    Do you have some form of IM to make things easier?

    Cheers CR
     
  17. macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #17
    I don't use Automator so I'm not sure if this will work unaltered with your workflow. The way I have it is that the script figures out which items should be selected in your "originals" folders and then at the end it makes that selection in the Finder for you. Your Automator workflow should add a "Get Selected Finder Items" item to the top.

    Now here's the part I don't know about your workflow. Will it take all of the files and process them? If it wants one per run then uncomment the "select aBItem" and comment out the two lines with comments at the end of them. Also add the call to your automator workflow after the "select aBItem" line.

    Hope this helps or gets you close. Post questions here and I'll try to answer them.

    Code:
    set folderA to choose folder with prompt "Choose your processed files folder"
    set folderB to choose folder with prompt "Choose your original files folder"
    
    tell application "Finder"
    	set theAItems to every file of folderA whose name extension is "jpg"
    	set theBItems to every file of folderB whose name extension is "jpg"
    	set AppleScript's text item delimiters to "-01.jpg"
    	set toselectList to {}
    	
    	repeat with anAItem in theAItems
    		set baseName to text item 1 of (name of anAItem as text)
    		set baseName to (baseName as string) & ".jpg"
    		open folderB
    		repeat with aBItem in theBItems
    			if name of aBItem is baseName then
    				-- select aBItem
    				-- call Automator here
    				set toselectList to toselectList & (aBItem as alias) -- comment this out
    			end if
    		end repeat
    	end repeat
    	
    	set selection to toselectList -- comment this out
    end tell
    
    -numero
     
  18. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #18
    Oooh that looks great.

    Firstly could you add more "delimiters" because there are "thumb_IMG_XXXX-01.jpg" and "normal_IMG_XXXX-01.jpg" and those do not have to be selected, just "IMG_XXXX-01.jpg".

    Secondly, is this applescript? I tried it in the script utility and it seemed to work up until parameter of the folders. I tried copying the locations of folders to replace "FolderA" but it just threw a strop :p

    Am I supposed to put this in a file or what? :eek::eek::confused:

    As for the process, it has to run my workflow (file name: "1280/800 - 60% - Concorde Photos"), on all the selected original images, be it 1, 10 or 100 of them.

    A popup box to let me select the two folders would be cool as I could drag and drop each one onto the browse window.

    Does that help? :)

    Thanks CR :)

    Edit: I've got it to do the pop-up select folders thing and it brings up the second folder but doesn't select anything? Also is there a way of setting where the starting folder is for each one instead of me having click all the way back through to each folder?

    Cheers CR
     
  19. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #19
    Anyone??

    Need to get this working now really :(
     
  20. macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #20
    I just re-read your post. I got some of my instructions wrong. I think my script does the opposite of what you want. No big deal. Just have to reverse some of the logic. I don't think I can get to it during the week, but I could work on it this weekend -- unless someone beats me to it.

    Is this Automator workflow proprietary? It would help if I could get a copy to see how it works. I'm not sure on how to get the files I select into Automator. I'm sure it can be done and it may be (and probably is) very simple. I've just never done this before.

    If you can send the workflow then send it to my email which is the login name on this site at mac.com.

    -numero
     
  21. macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #21
    I think this one will do what you want.

    First make a change to your Automator workflow. Replace the first action which is "Get Specified Finder Items" with "Get Selected Finder Items".

    Copy this script into the script editor and run it. Select your FolderA at the first prompt and FolderB at the second. When the script is done it will open your FolderB and have the files selected that have matches in FolderA. Don't touch anything. Just run your Automator Workflow and the selected images will be processed.

    Make sure that the first line inside of the "Tell Finder" block looks like this:

    set theAItems to every file of folderA whose name extension is "jpg" and name starts with "IMG"

    The preview here chops it off.

    Let me know if this doesn't work as expected.

    -numero

    Code:
    set folderA to choose folder with prompt "Choose your PROCESSED files folder"
    set folderB to choose folder with prompt "Choose your ORIGINAL files folder"
    
    tell application "Finder"
    	set theAItems to every file of folderA whose name extension is "jpg" and name starts with "IMG"
    	set theBItems to every file of folderB whose name extension is "cr2"
    	set AppleScript's text item delimiters to "-"
    	set toselectList to {}
    	
    	repeat with anAItem in theAItems
    		set baseName to text item 1 of (name of anAItem as text)
    		set baseName to (baseName as string) & ".CR2"
    		repeat with aBItem in theBItems
    			if name of aBItem is baseName then
    				set toselectList to toselectList & (aBItem as alias)
    			end if
    		end repeat
    	end repeat
    	open folderB
    	set selection to toselectList
    end tell
     

Share This Page