Help with a PDF export script

Thanks to the estimable @Alexander_Ploetz, I’ve managed a script for exporting a PDF which automatically assigns a fixed location for the export.

I can make a working script for a one-page PDF and another for a two-page PDF, but what I can’t seem to do is make the script work regardless of the number of pages in the layout. If the value doesn’t match the number of pages in the layout, nothing happens.

Any users with knowledge of scripting able to give some input? Thanks!

local app=DoApp.DoApp()
app:doCommand([[Print.PrintWithCurrentSettingsInternal?OpenScoreID=0&PrintingControllerID=0&UseSystemPrint=0]])
app:doCommand([[File.Print?PrintJob=<\?xml version="1.0" encoding="utf-8"\?>
<name/>
<layoutprintrecipe>
  <layoutid>0</layoutid>
  <numpages>1</numpages>
  <pageswithoptions>
    <pagerange>
      <firstpage_index>1</firstpage_index>
      <firstpage_number>1</firstpage_number>
      <lastpage_index>1</lastpage_index>
    </pagerange>
    <printoptions>
      <Border>
        <value>false</value>
        <indeterminate>false</indeterminate>
      </Border>
      <CollateCopies>
        <value>true</value>
        <indeterminate>false</indeterminate>
      </CollateCopies>
      <CropMarks>
        <value>false</value>
        <indeterminate>false</indeterminate>
      </CropMarks>
      <CustomScaleFactorPercent>
        <value>100</value>
        <indeterminate>false</indeterminate>
      </CustomScaleFactorPercent>
      <DateAndTime>
        <value>false</value>
        <indeterminate>false</indeterminate>
      </DateAndTime>
      <Destination>
        <value>kGraphics</value>
        <indeterminate>false</indeterminate>
      </Destination>
      <DuplexEdgeLandscape>
        <value>kFlipAutomatically</value>
        <indeterminate>false</indeterminate>
      </DuplexEdgeLandscape>
      <DuplexEdgePortrait>
        <value>kFlipAutomatically</value>
        <indeterminate>false</indeterminate>
      </DuplexEdgePortrait>
      <DuplexMode>
        <value>kSingleSided</value>
        <indeterminate>false</indeterminate>
      </DuplexMode>
      <DuplexReverseOrderOfOutwardPages>
        <value>false</value>
        <indeterminate>false</indeterminate>
      </DuplexReverseOrderOfOutwardPages>
      <FinalPageOrientation>
        <value>kPortrait</value>
        <indeterminate>false</indeterminate>
      </FinalPageOrientation>
      <FinalPageSize>
        <value>Letter</value>
        <indeterminate>false</indeterminate>
      </FinalPageSize>
      <GraphicColours>
        <value>kColour</value>
        <indeterminate>false</indeterminate>
      </GraphicColours>
      <GraphicDestinationFolder>
        <value>C:/Users/Dan Laptop/Dropbox (Grace Immanuel)/Professional/Hymnworks/Current Hymnworks Projects/1 Master PDFs</value>
        <indeterminate>false</indeterminate>
      </GraphicDestinationFolder>
      <GraphicFormat>
        <value>kPDF</value>
        <indeterminate>false</indeterminate>
      </GraphicFormat>
      <GraphicResolution>
        <value>150</value>
        <indeterminate>false</indeterminate>
      </GraphicResolution>
      <JobType>
        <value>kNormal</value>
        <indeterminate>false</indeterminate>
      </JobType>
      <NumCopies>
        <value>1</value>
        <indeterminate>false</indeterminate>
      </NumCopies>
      <NumPages>
        <value>1</value>
        <indeterminate>false</indeterminate>
      </NumPages>
      <PageOrientation>
        <value>kPortrait</value>
        <indeterminate>false</indeterminate>
      </PageOrientation>
      <PageRange>
        <value>kAllPages</value>
        <indeterminate>false</indeterminate>
      </PageRange>
      <PageRanges>
        <value>1 - 1</value>
        <indeterminate>false</indeterminate>
      </PageRanges>
      <PageSize>
        <value>Letter</value>
        <indeterminate>false</indeterminate>
      </PageSize>
      <PrintFinalPageSeparately>
        <value>false</value>
        <indeterminate>false</indeterminate>
      </PrintFinalPageSeparately>
      <PrinterDescription>
        <value>Adobe PDF</value>
        <indeterminate>false</indeterminate>
      </PrinterDescription>
      <Scaling>
        <value>kFitToPaper</value>
        <indeterminate>false</indeterminate>
      </Scaling>
      <ViewOptions>
        <value>false</value>
        <indeterminate>false</indeterminate>
      </ViewOptions>
      <Watermark>
        <value>false</value>
        <indeterminate>false</indeterminate>
      </Watermark>
      <WatermarkText>
        <value/>
        <indeterminate>false</indeterminate>
      </WatermarkText>
      <defaultgraphicdestinationdirectory>C:\\Users\\Dan Laptop\\Dropbox (Grace Immanuel)\\Professional\\Hymnworks\\Current Hymnworks Projects\\0 Master Dorico files</defaultgraphicdestinationdirectory>
    </printoptions>
  </pageswithoptions>
</layoutprintrecipe>
&OpenScoreID=0]])

Unfortunately, from a quick read of the relevant code, I don’t think you can do this: when Dorico creates the print “recipe”, it populates the page range with the appropriate number of pages based on the actual layout you’re printing, and I don’t think that’s something you can practically access.

Ok thanks Daniel. At the moment I have one key command to export a 1-page PDF, and another to export a 2-page PDF, so I’ll just leave it as is. It sounds a bit narrow, but it’s already a great help to my workflow.

I noticed that the Jump bar isn’t accessible from the Print mode, though there are a couple of print commands in there. Anyhow, if the Jump bar went deeper with some of the functionality perhaps I mention in this thread, it might accomplish what you’re trying to do

Edit: oh, you’re just trying to create a PDF, well anyhow …