6 Replies Latest reply on Nov 6, 2011 1:29 AM by yajiv_viki

    Its possible to convert Apple script to Java script

    yajiv_viki Level 2



      Please Help me anyone to do that script.


      its possible to convert below mentioned Apple script to Java Script.


      Thanks in advance.


      Help me......!





      tell me to addImageLabels()


      on addImageLabels()

                tell application "Adobe InDesign CS5"


                          set numberAdded to 0


                          set enable redraw of script preferences to true


                          set currentFonts to (get name of every font)

                          if currentFonts does not contain fontname then

                                    display dialog "The font \"" & fontname & "\" is not active on your system." buttons {"Continue anyway", "Cancel"} default button 2

                          end if


                          tell document 1


        -- get a list of unique page IDs in this document

                                    set allpageids to my getPageIds()

                                    repeat with p from 1 to (length of allpageids)

                                              set pgid to item p of allpageids


        -- loop through these, getting a list of unique page item IDs to inspect

                                              tell page id pgid

                                                        set pageitems to (get id of every page item)

                                                        repeat with i from 1 to (length of pageitems)

                                                                  set pid to item i of pageitems

                                                                  tell page item id pid


        -- certain boxes will fail to yield a content type, whatever

                                                                                      if content type is graphic type then

                                                                                                set c to class

                                                                                                set i to id

        -- get the name of the link, i.e. the filename, subject to labelFormat (full name, first six chars, etc.)

                                                                                                set gn to my getImageName(pgid, c, i)

                                                                                                if (gn is not "Empty") and (gn is not "") then

                                                                                                           set b to visible bounds

                                                                                                           set h to (item 3 of b) - (item 1 of b)

                                                                                                           set newtop to (item 1 of b) + (h / 2)

                                                                                                           set item 1 of b to newtop

                                                                                                           set w to (item 4 of b) - (item 2 of b)

                                                                                                           if w < minwidth then

                                                                                                                     set item 4 of b to ((item 4 of b) + 0.2)

                                                                                                                     set item 2 of b to ((item 2 of b) - 0.2)

                                                                                                           end if


                                                                                                           set l to (make new text frame at beginning of page id pgid with properties {visible bounds:b, fill color:fillcolor, contents:gn, label:"imagelabel"})

                                                                                                           tell l

                                                                                                                     tell paragraph 1

                                                                                                                               set justification to center align


                                                                                                                                         set applied font to fontname

                                                                                                                               end try

                                                                                                                               set point size to fontsize

                                                                                                                               set fill color to textcolor

                                                                                                                     end tell



                                                                                                                     set inset spacing of text frame preferences to ((insetspacing as string) & " in") as string

        fit given frame to content


                                                                                                                     set numberAdded to numberAdded + 1

                                                                                                           end tell

                                                                                                end if

                                                                                      end if

                                                                            end try

                                                                  end tell

                                                        end repeat

                                              end tell

                                    end repeat -- allpageids

                          end tell -- document 1

        display dialog "Added " & numberAdded & " labels." buttons {okButton} default button 1 giving up after 10 with title scriptName

                end tell -- InDesign

      end addImageLabels


      on getPageIds()

                tell application "Adobe InDesign CS5"

                          tell document 1

                                    tell master spread 1

                                              set masterpageids to (get id of every page)

                                    end tell

                                    set docpageids to (get id of every page)

                          end tell

                end tell

                return masterpageids & docpageids

      end getPageIds


      on getImageName(int1, cla1, int2)

                tell application "Adobe InDesign CS5"

                          tell document 1

                                    tell page id int1


                                              if cla1 is rectangle then

                                                        set imagename to (name of item link of graphic 1 of rectangle id int2)

                                              else if cla1 is polygon then

                                                        set imagename to (name of item link of graphic 1 of polygon id int2)


                                                        return "Unknown"

                                              end if



                                                        if (labelformat is "First six characters") then

                                                                  return (characters 1 thru 6 of imagename) as string

                                                        else if (labelformat is "Base name of linked file") then

                                                                  set op to offset of "." in imagename

                                                                  return (characters 1 thru (op - 1)) of imagename as string


                                                                  return imagename

                                                        end if

                                              on error

                                                        return "Empty"

                                              end try


                                    end tell

                          end tell

                end tell

      end getImageName