Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Trevor-/e6afcac19c2aa67c77071e01165caabf to your computer and use it in GitHub Desktop.
Save Trevor-/e6afcac19c2aa67c77071e01165caabf to your computer and use it in GitHub Desktop.
This will run a remote script on InDesign. It curls the script and then executes it.
////////////////////////////////////////////////////////////
// For InDesign Windows !!!!! //
// See https://forums.adobe.com/message/10632451#10632451 //
// By Trevor http://creative-scripts.com //
////////////////////////////////////////////////////////////
var remoteCodeUrl, vbs, appleScript, remoteScript;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Change to desired URL, must be raw, i.e. no HTML, can use github / patesbin to host make sure to include the /raw part in the link //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
remoteCodeUrl = 'https://gist.githubusercontent.com/Trevor-/a297b25e270c2e19d3ba12b5406212d9/raw';
if ($.os[0] === 'M') { // [M]ac
appleScript = "do shell script \"curl 'remoteCodeUrl'\"".replace("remoteCodeUrl", remoteCodeUrl);
remoteScript = app.doScript(appleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE);
} else { // [W]indows
vbs = [
// Create Shell Object
'Set shell = CreateObject("WScript.Shell")',
// Execute curl in powershell
'Set executor = shell.Exec("powershell.exe -windowstyle hidden Invoke-WebRequest -Uri remoteCodeUrl | Select-Object -ExpandProperty Content")'.replace("remoteCodeUrl", remoteCodeUrl),
// Capture stdout
'executor.StdIn.Close',
// "Forward" result to jsx engine
'returnValue = executor.StdOut.ReadAll',
].join('\n');
remoteScript = app.doScript(vbs, ScriptLanguage.VISUAL_BASIC);
}
/////////////////////////////////////
// Change as per remoteScript //
// This works for the URL provided //
/////////////////////////////////////
// Set script args
app.scriptArgs.setValue("scriptArg1", "Hello");
// Set environmental vars
$.setenv("envVar1", "World");
// Run the "remote" script
app.doScript(remoteScript, ScriptLanguage.JAVASCRIPT);
// Share functions and vars
// "blah" and "testVar" are grabbed from the remote script
blah('Demo by: ', testVar);
/* Some sources
https://github.com/PowerShell/PowerShell/issues/3028
https://stackoverflow.com/questions/36941027/how-to-return-powershell-variable-to-vbscript
https://forums.adobe.com/thread/2000455
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment