• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to translate export pdf from applescript to extend scriipt

Engaged ,
Dec 04, 2018 Dec 04, 2018

Copy link to clipboard

Copied

Hi All

I use the below applescript to export a PDF from Indesign CC 2019 to a folder on my desktop that begins with "Q", it works

well and as expected, what I am wanting to do is try the same set up in extend script, my problem is I don't no how to write

it, can some one please help translate this to extend script, using the same variables etc, and with out user interaction?

thank you in advance.

tell application "Finder"

    set myFolder to POSIX path of ((folders of desktop whose name begins with "Q") as string)

end tell

tell application id "com.adobe.InDesign"

    set myDoc to active document

    set docName to name of myDoc as string

   

    set _dest to myFolder as Unicode text

    delete unused swatches of document 1

    set screenSettings to PDF export preset "USE THIS TO DISTILL-1"

    set page range of PDF export preferences to all pages

   

    set PathToDesktop to file path of document 1 as string

    set this_folder to (PathToDesktop) as alias

    export document 1 format PDF type to (_dest & docName & ".pdf") using screenSettings without options

    close document 1 saving yes

    tell PDF export preferences

        set view PDF to true

    end tell

end tell

TOPICS
Scripting

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 04, 2018 Dec 04, 2018

Hi Kevin,

Try the following, i have removed some unused variables like PathToDesktop and this_folder. i have not added anything extra like error handling conditions, i have tried to keep the code as similar to the one you have. Give it a try and let me know if something is missing, i am not proficient in Applescript so i may have skipped something

function isOurFolder(arg)

{

     if(arg.name.match(/^Q.*?/))

          return true

     else

          return false

}

var myFolder = Folder.desktop.getFiles(is

...

Votes

Translate

Translate
Contributor ,
Dec 04, 2018 Dec 04, 2018

Copy link to clipboard

Copied

Hi,

     I have run the script and its exported pdf in the desktop folder which name starts with "Q".  When desktop contains more than one folder, name starts with "Q"? Its throwing an error.  In this case, how to will you decide the destination folder?

     Better choose or define the path.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 04, 2018 Dec 04, 2018

Copy link to clipboard

Copied

Hi SUdha

thanks for replying, my work flow dictates I only have 1 folder on desktop beginning with Q, no need for error check

Regards

Kevin Parrott

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2018 Dec 04, 2018

Copy link to clipboard

Copied

Hi Kevin,

Try the following, i have removed some unused variables like PathToDesktop and this_folder. i have not added anything extra like error handling conditions, i have tried to keep the code as similar to the one you have. Give it a try and let me know if something is missing, i am not proficient in Applescript so i may have skipped something

function isOurFolder(arg)

{

     if(arg.name.match(/^Q.*?/))

          return true

     else

          return false

}

var myFolder = Folder.desktop.getFiles(isOurFolder)

var myDoc = app.activeDocument

var docName = myDoc.name

var _dest = myFolder[0].fsName

try

{

     var unusedSwatches = myDoc.unusedSwatches

     for(var i = 0; i < unusedSwatches.length; i++)

          unusedSwatches.remove()

}

catch(e){}

var screenSettings = app.pdfExportPresets.itemByName("USE THIS TO DISTILL-1")

app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES

app.pdfExportPreferences.viewPDF = true

app.activeDocument.exportFile(ExportFormat.PDF_TYPE, _dest + "/" + docName + ".pdf", false, screenSettings)

myDoc.close(SaveOptions.YES)

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 04, 2018 Dec 04, 2018

Copy link to clipboard

Copied

Hi Manan,

     Really nice... It is works same as apple script which he post.

     arg for the function  isOurFolder is Folder.desktop.getFiles?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

isOurFolder is a callback function that will be called with each File or Folder as arg within the desktop folder.

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Hi Manan

thank you for the code,appreciate the time taken to translate, it slips perfectly into my work flow, and it's faster than the apple script I was using, which was the main reason for doing this.

One thing id like to change is when the PDF is exported it looks like this Q12345-ABCD-.indd.pdf , id like to eliminate the .indd suffix, is this doable within the code you provided?

cheers

Kevin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Hi Manan,

     Thanks for your explanation...

Hi Kevin,

    function isOurFolder(arg)

    {

         if(arg.name.match(/^Q.*?/))

              return true

         else

              return false

    }

    var myFolder = Folder.desktop.getFiles(isOurFolder)

    var myDoc = app.activeDocument

   var docName = myDoc.name.replace(".indd",".pdf")               // replaced .indd to .pdf

    var _dest = myFolder[0].fsName

    alert("docName " + docName)

    try

    {

         var unusedSwatches = myDoc.unusedSwatches

         for(var i = 0; i < unusedSwatches.length; i++)

              unusedSwatches.remove()

    }

    catch(e){}

    var screenSettings = app.pdfExportPresets.itemByName("OUP_US")

    app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES

    app.pdfExportPreferences.viewPDF = true

    app.activeDocument.exportFile(ExportFormat.PDF_TYPE, _dest + "/" + docName, false, screenSettings) 

    myDoc.close(SaveOptions.YES)

Pls check.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Hi Sudha

thanks for your input

I am now getting an error, I have an ope ID file, I then run the script

Adobe Indesign CC 2019 got an error: Cannot save to the file "Q12345",because it is already open

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Hi,

     Change this line to your preset file.

     var screenSettings = app.pdfExportPresets.itemByName("USE THIS TO DISTILL-1")

     Also check whether pdf file is already open.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Hi

I already changed over the preset to my one, and no pdf's are open, only the Indesign file

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

it appears that the Indesign file did not have the .indd suffix on it, I tried a file with the .indd suffix and it worked

is there a possibility to add a little error check to see if the .indd suffix is there or not ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Try the following line

var docName = myDoc.name.replace(/.indd$/i, "")

and let me know how it goes

P.S. :- Just change this line in the original script and not any other

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Hi Sudha,

In your code we could have the following issues.

  • If the filename has .indd multiple times it will replace the first instances of indd with pdf only. For ex. ABC.inddDEF.indd would change to ABC.pdfDEF.indd
  • In case the filename does not have any extension then a pdf without pdf extension would be produced, because replace will do no change and the filename that is created finally for export is not adding the .pdf extension.

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 05, 2018 Dec 05, 2018

Copy link to clipboard

Copied

Hi Manan,

     Thanks for pointing out the issues and for explanation.  It useful to avoid such issues.

     Thank you...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 06, 2018 Dec 06, 2018

Copy link to clipboard

Copied

LATEST

Hi Manan

Thank you very much for your time and knowledge, very much appreciated, the final change worked perfectly, it seems

a lot faster than the apple script.

Sudha, thank you for your time and input

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines