Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacBH928

macrumors 604
Original poster
May 17, 2008
7,472
3,245
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.
 

kryten2

macrumors 65816
Mar 17, 2012
1,080
87
Belgium
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.
 

Attachments

  • Screen Recording-480P.zip
    2.4 MB · Views: 408
Last edited:

MacBH928

macrumors 604
Original poster
May 17, 2008
7,472
3,245
You should also quote the file path for the shell script, otherwise it will fail if there are spaces in the name.

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.
[doublepost=1465206654][/doublepost]
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.

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
 

kryten2

macrumors 65816
Mar 17, 2012
1,080
87
Belgium
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?
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.

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?
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/

When you say do not use this on a lot of files, how much is a lot? And why would it not work.
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.
Thanks a lot man
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?
 
Last edited:

MacBH928

macrumors 604
Original poster
May 17, 2008
7,472
3,245
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?

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
 
Last edited:

superscape

macrumors 6502a
Feb 12, 2008
933
222
East Riding of Yorkshire, UK
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/

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.
 

kryten2

macrumors 65816
Mar 17, 2012
1,080
87
Belgium
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

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.

Thanks for the name check, kryten2!

:D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.