Last active
September 21, 2018 06:51
-
-
Save Trevor-/a5de06d41e28936ad72fe3e348bddd33 to your computer and use it in GitHub Desktop.
Curls And Executes a remote script in InDesign
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////// | |
// For InDesign Windows !!!!! // | |
// See https://forums.adobe.com/message/10632451#10632451 // | |
// By Trevor http://creative-scripts.com 21 Sep 18 // | |
//////////////////////////////////////////////////////////// | |
// https://gist.github.com/Trevor-/a5de06d41e28936ad72fe3e348bddd33 | |
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-/55297356e5728f57c2225df16a8e8b0e/raw'; | |
// "aVarFromLocalToRemote" is used in the "remote" script | |
var aVarFromLocalToRemote = 'A Var From Local To Remote'; | |
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, these can be fetched by the remote | |
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 "aVarFromRemoteToLocal" are grabbed from the remote script | |
blah('Demo by: ', aVarFromRemoteToLocal); | |
/* 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
This shows how to curl and execute a script in InDesign with various methods of sharing vars / functions between the local and remote in both directions.
See https://forums.adobe.com/message/10632451#10632451 for background