VBScript created by Indesign Extended Script, does not execute part of the code - WScript.Shell run

346 Views Asked by At

I have a VBScript that is created by Indesign JSX (Extended Script). It runs a bash command (DOS) to convert an ODT to PDF. However, via Indesign this part (shell.Run) does not work. I put two MsgBox, one before and one after and both run. Only the PDF conversion part that doesn't.

The VBS file is saved on the Desktop, if I run it by clicking on the file, it runs all the instructions. The video serves to show that inside indesign it doesn't run, already in explorer, it works 100%. https://youtu.be/0-O7KWVIOdo

Code JSX

    function fnc_ODT_RunVbsThroughJs(){
    //  community.adobe.com/t5/illustrator-discussions/run-vbscript-through-javascript-in-illustrator/td-p/10082969
    var str = 
        'Set myApp = CreateObject("InDesign.Application")\r\n' + 
        'Set oFSO = CreateObject("Scripting.FileSystemObject")\r\n'+
        'Set shell = CreateObject("WScript.Shell")\r\n'+
        'MsgBox "Bem vindo seu Codorna"\r\n' + 
        'shell.Run  """C:\\Program Files (x86)\\LibreOffice 4\\program\\swriter.exe"" --headless --convert-to pdf 4001278.odt"\r\n' +
        'MsgBox "Tchau seu Codorna"'
        ;

    var vbsFile = new File(Folder.desktop + '/codorna.vbs');

    try {
        vbsFile.open('w');
        vbsFile.write(str);

    } finally {
        vbsFile.close();
    }

    vbsFile.execute();
}

Code VBS

Set myApp = CreateObject("InDesign.Application")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
MsgBox "Bem vindo seu Codorna"
shell.Run  """C:\Program Files (x86)\LibreOffice 4\program\swriter.exe"" --headless --convert-to pdf 4001278.odt"
MsgBox "Tchau seu Codorna"

UPDATE 07/07/2022.

I tried others Folders @Yuri Khristich.

I tried BAT, same problem... No... worse:

  • by indesign or by clicking Windows explorer, do not work.
  • by cmd: c:...\ODTtoPDF.bat works 100%

But don't tried notepad, I will. Only to see run a .exe file.

I need to convert ODT to PDF.

Apparently, the best to this is soffice or swriter.

Before, I tried to convert by word, but some files just crash in word, it don't happens with swriter.

07/07/2022 Second round

  • @KJ, I tried your idea, nothing diferent happens :(, I renamed the Resource file, reopened Indesign with administrative privileges, the resource was reinstalled, but the problem continues

I removed the parameters and worked. Unfortunately I need the parameters to generate the pdf.

Indesign JSX

function fnc_ODT_RunVbsThroughJs(){
    //  community.adobe.com/t5/illustrator-discussions/run-vbscript-through-javascript-in-illustrator/td-p/10082969
    var str = 
        'Set oFSO = CreateObject("Scripting.FileSystemObject")\r\n'+
        'Set shell = CreateObject("WScript.Shell")\r\n'+
        'MsgBox "Bem vindo seu Codorna"\r\n' + 
        'shell.Run  """C:\\Program Files (x86)\\LibreOffice 4\\program\\swriter.exe""" \r\n' +
        //'shell.Run  "C:\\PROGRA~2\\LIBREO~1\\program\\swriter.exe --headless --convert-to pdf 4001278.odt"\r\n' +
        //'shell.Run   "C:\\Windows\\System32\\notepad.exe"' 2022-07-07 NOTEPAD WORKS

        'MsgBox "Tchau seu Codorna"'
        ;

    //var vbsFile = new File(Folder.desktop + '/codorna.vbs');
    var vbsFile = new File(scriptFolder + '/codorna.vbs');

    try {
        vbsFile.open('w');
        vbsFile.write(str);

    } finally {
        vbsFile.close();
    }

    vbsFile.execute();
}

VBS generated and run by Indesign (codorna.vbs)

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
MsgBox "Bem vindo seu Codorna"
shell.Run  """C:\Program Files (x86)\LibreOffice 4\program\soffice.exe""" 
MsgBox "Tchau seu Codorna"
0

There are 0 best solutions below