0

Please explain how to make applescript understand I want to select all images on the active page (which in my case are going to be one), to resize the image and fit frame to content.

tell application "Adobe InDesign CS6"
    set myPagecount to count pages of active document
    repeat with i from 1 to myPagecount
        set thisImage to select every graphic frame of page i
        tell content of thisImage
            set height to "11in"
            set width to "8.5in"
            fit given frame to content
        end tell
    end repeat
end tell

This obviously doesn't work...

Thanks!

Mauritz
  • 117
  • 12

2 Answers2

1

Just to give you some ideas:

tell application "Adobe InDesign CS5.5"
    activate
    set myPagecount to count pages of active document
    tell active document    
        set myPage to page 1
        tell page myPage
            tell item 1 of all graphics of myPage
                set geometric bounds of it to {10, 10, 0, 0}
            end tell
        end tell
    end tell
end tell

Just reference your page and loop through the collection of all graphics. You will need to change values for geometric bounds, use quotation marks for inches ("8.5in").

=================================

Edited:

The code above actually resizes graphics/pdf inside the frame. I added 2 versions - one for the pdf and one for the frame. You need to set your values in geometric bounds

tell application "Adobe InDesign CS6"
    activate
    set myPagecount to count pages of active document
    tell active document
        set myPage to page 1
        tell page myPage
            tell item 1 of all graphics of myPage
                set geometric bounds of it to {100, 100, 0, 0}
            end tell
            tell text frame 1 of myPage
                set geometric bounds of it to {100, 100, 0, 0}
            end tell
        end tell
    end tell
end tell
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23
  • 1
    Sorry, what does not work? I noticed I am referring to CS5.5, did you change it to 6? Try to change geometric bounds, you might have different defaults. I tried this script before I posted it and spent some time trying to help. I did not post ready-made solution for you, this is just a sample. You need to read and understand the code. E.g. Do you actually have a graphic frame on the first page? Just saying it does not work does not encourage me or someone else to continue. – Nicolai Kant Feb 23 '15 at 16:58
  • Ok. I have a placed a PDF file in Indesign and I want to change its width to 11in and its height to 8.5in. Afterwards I want the frame to fit the actual PDF. I thought that would be clear from the pseudo-code in my question... Every page only has one rectangle in it - the PDF file I placed. So yes, that is a graphic frame I believe... BTW: I didn't change it to CS6 - it was like that from the beginning... – Mauritz Feb 23 '15 at 17:14
  • 5.5 is my version and appeared in my code, if you run it you need to replace it with 6 - which is your version of InDesign. Sorry, that was not clear. – Nicolai Kant Feb 23 '15 at 17:52
  • No it is not clear when you are saying it does not work as a comment. Do you get an error message when you run my script? It does not run at all? Computer goes up in flames? Are you expecting me to post a full re-write so you can just copy and paste? When I run your script "graphic frame" comes up as an error, so I am suggesting to loop through items of "all graphics" for the page or reference item 1 if you only place one frame. – Nicolai Kant Feb 23 '15 at 18:00
  • Yay! It worked! The text frame didn't work so I will put the final result in my answer. Thanks a lot and thanks for the patience ;-) – Mauritz Feb 23 '15 at 19:36
  • You are welcome. I will have to try it on CS6 as in CS5.5 it seems to resize the graphics inside the container and not the container itself. Thanks for feedback and answer flag. – Nicolai Kant Feb 24 '15 at 10:04
1

This is the final answer - thanks to nicolai.kant!

tell application "Adobe InDesign CS6"
    set myPagecount to count pages of active document
    tell active document
        repeat with i from 1 to myPagecount
            set myPage to page i
            tell page myPage
                tell item 1 of all graphics of myPage
                    set geometric bounds of it to {"8.5in", "11in", 0, 0}
                    fit given frame to content
                end tell
            end tell
        end repeat
    end tell
end tell
Mauritz
  • 117
  • 12