Can I do this with Automator?

Discussion in 'Mac Programming' started by MacBH928, Jun 4, 2016.

  1. MacBH928 macrumors 68020

    MacBH928

    Joined:
    May 17, 2008
    #1
    So I don't know how to use this thing but can you please tell me if this is possible.

    I want a script that will go through each file in a folder - grab its info (command+I), then take a screenshot of that window only and save it in the same folder.

    If the screenshot of the Get Info window is not possible I am willing to accept a full screenshot then I will just manually crop them.
     
  2. kryten2, Jun 4, 2016
    Last edited: Jun 5, 2016

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Yes but here's an AppleScript example :

    Code:
    set this_folder to (choose folder with prompt "Pick the folder containing the files to process:") as string
    
    tell application "System Events"
        set these_files to every file of folder this_folder whose visible is true
    end tell
    
    repeat with i from 1 to the count of these_files
        set this_file to (item i of these_files as alias)
        set this_info to info for this_file
        set fileName to name of this_info
        if visible of this_info is true and alias of this_info is false then
            -- insert actions here for: this_file
            if i = 1 then
                tell application "System Events"
                    set fileContainer to POSIX path of container of this_file
                end tell
            end if
            tell application "Finder"
                if i = 1 then
                    activate
                end if
                --set infoWindow to information window of this_file
                open the information window of this_file
                set the windowId to id of information window of this_file
            end tell
            do shell script "screencapture -T 1 -ol" & windowId & space & quoted form of (fileContainer & "/" & fileName & "-screencapture.jpg")
            tell application "Finder" to close the information window of this_file
        end if
    end repeat
    
    Note : Briefly tested on Mavericks. Don't use this on a lot of files.
     

    Attached Files:

  3. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #3
    You should also quote the file path for the shell script, otherwise it will fail if there are spaces in the name.
     
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
  5. MacBH928 thread starter macrumors 68020

    MacBH928

    Joined:
    May 17, 2008
    #5
    Quote which file path to where exactly? It will fail if there are spaces in which name, the folder with the files or the files themselves?

    Sorry I know nothing about this.
    --- Post Merged, Jun 6, 2016 ---
    This is EXACTLY what I am looking for. Did you write this for me or is there a place online with all kinds of scripts?
    Are you willing to write me a full proof one for a small amount of money? If not, do you know where I can get someone to do it for me?
    I am currently running 10.9 and upgrading as soon as the new MBP are out.

    When you say do not use this on a lot of files, how much is a lot? And why would it not work.

    Thanks a lot man
     
  6. kryten2, Jun 6, 2016
    Last edited: Jun 6, 2016

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
    Of course I wrote this for you, I just gave you one of many possible solutions to your problem. There are lots of places online where you can find all kind of scripts like macscripter.net or stackoverflow.

    Nope, I do this for fun. You can try sending a PM to forum member superscape or visit his site at https://www.ghostotter.com/custom-development/

    Thousands of files. I didn't say it wouldn't work, it would be slow. The screencapture command defaults to a 5 second wait before the screen capture is taken. I already changed the default to 1 second by using -T 1. Perhaps you can try to change it to something like -T 0.5. I'm not at home for the moment so I can't test this.
    You're welcome.
    I'm left with only one question. Why would you want to do something like this? What kind of info are you looking for in those files?
     
  7. MacBH928 thread starter macrumors 68020

    MacBH928

    Joined:
    May 17, 2008
    #7
    I have files with sentimental value and a lot of memories. I want to save their info and creation date so I always know when were they from. Kind of like dates on photos. I am afraid that during some sort of file transferring this info would be lost.

    Thanks again for helping me out
     
  8. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #8
    Thanks for the name check, kryten2!


    MacBH928: Having a screen grab of the info window seems like a bit of a speed bump and makes things quite a bit fiddlier. Would it be acceptable to have a text/html file instead of a screen grab, so long as it contained the info you need? If so, you could do it pretty quickly with a few lines of shell script (which could be incorporated into an Automator action for ease of use if necessary). Drop me a PM if you'd like to discuss it as a custom development project.
     
  9. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #9
    It's getting clear now. So there's really no need to use the info window and taking a screen capture. You could use the mdls command in a shell script to get the info you want. I'm guessing superscape is probably thinking along the same lines.


    :D
     
  10. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #10
    Yup. Pretty much.
     

Share This Page