5 Replies Latest reply on Aug 1, 2016 2:33 PM by lepkemot

    Applying applescript to selected pages

    lepkemot Level 1

      Hi, how do I change the script below so it only applies to pages I have previously selected in Pages panel?

       

      tell application "Adobe InDesign CC 2015"

      activate

      set n to pages per document of document preferences of active document

      tell active document

      set c to 1

      repeat with i from 1 to n

      move page n to before page c

      set c to (c + 1)

      end repeat

      end tell

      display dialog "Done"

      end tell

       

      Thanks!

        • 1. Re: Applying applescript to selected pages
          Loic.Aigon Adobe Community Professional

          I don't thing a script can reach the user selection in the pages panel.

          • 2. Re: Applying applescript to selected pages
            S Hopkins Adobe Community Professional

            Hi,

             

            Why don't you just have the user enter the numbers for the pages to have the script applied to in a display dialog and then process the pages listed. Something like the following:

             

            set numberList to {}

            set userResponse to display dialog "Enter numbers for pages to process. Separate numbers with semicolon" default answer "1;4;7"

            set pageNumbers to text returned of userResponse

            set x to offset of ";" in pageNumbers

            if x > 0 then

              set oldDelim to AppleScript's text item delimiters

              set AppleScript's text item delimiters to ";"

              set numberList to text items of pageNumbers

              set AppleScript's text item delimiters to oldDelim

            else

              set pageNum to pageNumbers as number

              --maximum value below is number of pages in document

              if pageNum > 0 and pageNum < 100 then

                 set numberList to {pageNumbers}

               end if

            end if

            if numberList is not {} then

              tell application "Adobe InDesign CC 2015"

              set docRef to active document

              tell docRef

              set c to a reference to page 1

              repeat with i from 1 to length of numberList

              try

              move page (item i of numberList) to before c

              on error errStr

              activate

              display alert "Error " & errStr

              --do nothing

              end try

              end repeat

              end tell

              end tell

            display dialog "Done" giving up after 2

            end if

             

            Just a thought.

            • 3. Re: Applying applescript to selected pages
              lepkemot Level 1

              Hi S Hopkins, thanks for your reply. That's a good idea. Do you think it would be possible to input range of pages, for example "10-20" instead of listing single pages? Also, at the moment your script reverses the order but moves all pages to the beginning of document. Is it possible to reverse the order but keep pages in the same place within the document? For example: 1-2-3-4-5 becomes 1-4-3-2-5 if "2-4" input? Thanks again, T

              • 4. Re: Applying applescript to selected pages
                S Hopkins Adobe Community Professional

                Hi,

                Sure you can do both. To get a range of numbers from the user the following can be used. Try the following:

                 

                set minX to missing value

                set maxX to missing value

                set userResponse to display dialog "Enter page range. Separate maximum and minimum with hyphen" default answer "4-10"

                set pageNumbers to text returned of userResponse

                set x to offset of "-" in pageNumbers

                set len to length of pageNumbers

                if x > 0 then

                  set minX to (text 1 thru (x - 1) of pageNumbers) as number

                  set maxX to (text (x + 1) thru len of pageNumbers) as number

                end if

                {minX, maxX}

                 

                With this information you can move your pages using the following:

                 

                tell application "Adobe InDesign CC 2015"

                  tell document 1

                  set pageRef to page (minX - 1)

                  repeat with i from minX to maxX

                  move page i to after pageRef

                  end repeat

                  end tell

                end tell

                 

                To bullet-proof your script you will need to make sure that numbers entered are valid. (minX and/or maxX is not missing value, maxX is greater than minX, minX - 1 is not 0, etc.). I will leave that up to you.

                 

                Shirley Hopkins

                 

                • 5. Re: Applying applescript to selected pages
                  lepkemot Level 1

                  Thank you Shirley