12 Replies Latest reply on Jul 9, 2009 9:00 AM by liedzeit

    XML import preferences (AS)

    penyfai Level 1

      Having a problem getting an applescript to automate XML import.


      This is the way I've tried:


      tell application "Finder"

      set macname to get name of startup disk

      end tell



      tell application "Adobe InDesign CS3"


      set xsltpath to (macname & ":Users:TechMan:Desktop:Indd planning:Plan:CWtoINDDElements.xsl")

      set newdoc to make document with properties {document preset:"34x8"}

      set xmlpath to choose file with prompt "Select the XML"


      tell active document

      tell XML import preferences

      set allow transform to true

      set create link to XML to false

      set ignore unmatched incoming to true

      set ignore whitespace to true

      set import CALS tables to false

      set import style to merge import

      set import text into tables to false

      set import to selected to false

      set remove unmatched existing to false

      set repeat text elements to false

      set transform filename to xsltpath

      end tell


      import XML from xmlpath

      on error errMsg number errornumber

      display dialog "Ooops" & errornumber as text

      end try

      end tell

      end tell


      This part of a much larger script throws up an error stating that the "Stylesheet 'Andrews Mac:Users:TechMan:Desktop:Indd planning:Plan:CWtoINDDElements.xsl' specified in the XSLT processing instruction can not be found. File was imported without any transformations performed."


      Why? I know the file exists and is not locked or in use.


      When I import manually, everything runs perfectly.


      Please help, my head is about to explode again!

        • 1. Re: XML import preferences (AS)
          Thomas B. Nielsen Level 3

          I dont know AS, but have you tried to read the file into some var and then alerting or somehow displaying the contents?

          Just to debug if the file is actually not to be found by AS.


          In JavaScript i use this little script to give me the path to a file:


          // Alert file - JavaScript Document
          var myFile = File.openDialog("Choose a File");
          if((myFile != "")&&(myFile != null)){
              alert("Path: " + myFile + "\nType: " + myFile.type);


          Perhaps you can translate to a AS debug version.

          • 2. Re: XML import preferences (AS)
            penyfai Level 1

            Hi Thomas


            I've learnt a lot since my last posting, so thanks for putting me on the right track then.


            I have actually tried what you suggested. I had the same problem with the XML file path when it was hard coded. The object being that I just wanted to replace a static xml doc.


            Where I've got      set xmlpath to choose file with prompt "Select the XML"
            i also had             set xsltpath to choose file with prompt "Select the XSLT"

                                       log xsltpath --(this throws the value of xsltpath in to the results pane of AS)


            It still didn't work. It showed the correct path to the file but still failed when run through the script. Bizzare!


            The only other thing that I could try is to just define xsltpath as "CWtoINDDElements.xsl", due to the fact that I've told InDesign that I'm getting the XML from the same folder in the 'choose' function.


            I'm not connecting to my work VPN at 11.50pm, so I'll try again in the morning.


            Thanks Thomas. It's great to bounce ideas around.


            Best, Andrew

            • 3. Re: XML import preferences (AS)
              penyfai Level 1

              Ok, now I've tried adding the xsl to the Indesign package and just


              set transform filename to "CWtoINDDElements.xsl"


              Still the same error stylesheet ...path to this file (valid!)...can not be found.


              Does anyone else do the same in a script that works?


              Could it be that I've got this instruction from a CS4 manual - I'm using CS3?


              Can I tell the script to open the Import XML dialog when the command is sent?


              Is it worth pursuing in the push for automation?


              Is the world really flat....sorry, head gone now!

              • 4. Re: XML import preferences (AS)
                sstanleyau Level 4

                So hen you import manually, what do you get if you ask for the transform filename?



                Shane Stanley <sstanley@myriad-com.com.au>

                AppleScript Pro Sessions <http://scriptingmatters.com/aspro>

                • 5. Re: XML import preferences (AS)
                  penyfai Level 1

                  No error what-so-ever and a perfectly translated XML in the viewer.


                  I've taken the XML import preferences statements directly from and Adobe script, so I can only assume that it's correct.


                  The only extra that I haven't tried is to:


                  set transform parameters to {{"format", "1"}} (from the scripting guide)


                  This is because I'm trying to source a definition of this setting..... I've had my head in "A designer's guide..." and the Adobe Scripting guide and done a quick google. So far nothing...


                  Any ideas of how this works?

                  • 6. Re: XML import preferences (AS)
                    sstanleyau Level 4

                    You misunderstand me: after you do a successful import, what is returned when you run a script asking for the "transform filename of XML import preferences..."?

                    • 7. Re: XML import preferences (AS)
                      penyfai Level 1

                      Ah ha, sorry Shane. I'll give it a shot and let you know.....

                      • 8. Re: XML import preferences (AS)
                        penyfai Level 1

                        This is the result:


                        {file "Andrews Mac:Users:TechMan:Desktop:Indd planning:Plan:CWtoINDDElements.xsl"}

                        (*Andrews Mac:Users:TechMan:Desktop:Indd planning:Plan:CWtoINDDElements.xsl*)


                        Which is the value that I'm telling it to use in:


                        set transform filename to xsltpath


                        As I say, I'm at a loss now. But I'll still pursue the transform parameters line....

                        • 9. Re: XML import preferences (AS)
                          penyfai Level 1

                          Now tried:


                          set xsltpath to choose file with prompt "Select the XSLT" of type {"XML"}


                          This is interesting as the choose list excludes the xml and xslt files that exist in this location. It seems that the script doesn't recognise that these are xml files. As a test I've tried u/c & l/c xml & xsl and used "" around them. I've also tried without the parenthesis. All don't allow selection of the xml based files.

                          • 10. Re: XML import preferences (AS)
                            penyfai Level 1

                            Can't get this to work!


                            Tried to transform the XML externally and automate the import of the resultant XML file.


                            This didn't bring in the xml correctly.




                            Does anyone know if I can invoke the "Import XML..." menu selection from the file menu, using the existing applescript?



                            • 11. Re: XML import preferences (AS)
                              penyfai Level 1

                              No worries, used the following to invoke the actual Indesign open xml dialog:


                              set importxml to menu action "Import XML..."

                              invoke importxml


                              This is actually beneficial to this script and means it can be used for varying types of transformations


                              thanks to everyone who looked at this and pondered the situation. I hope these findings prove helpful to others.....

                              • 12. Re: XML import preferences (AS)
                                liedzeit Level 2

                                Interesting to go by menu action... I will try this.


                                Actually scripting XSLT is a bug on the Mac as I had to find out, works fine under Windows.