Skip to main content
Geppetto Luis
Legend
October 4, 2018
Question

Include Remote file in Windows

  • October 4, 2018
  • 1 reply
  • 607 views

I start from this discussion

use photoshop cc 2018

https://forums.adobe.com/thread/2537681

I thank Trevor for his help

I need to use .js or. jsx remotely

With mac everything works correctly

in windows it does not work

I would like to find a solution for this.

This topic has been closed for replies.

1 reply

Trevor:
Legend
October 4, 2018

Hi I moved to Photoshop Scripting which is the correct place for the thread.

The difference between Id doScript and Ps system is the doScript does execute visual basic and applescipt whereas system executes shell. doScript returns a result and system doesn't so it needs piping.

Below is not enterprise fail-safe stuff, that cost money.

Enjoy

// Downloads and executes a remote script in Photoshop

// See https://forums.adobe.com/thread/2537681 and https://forums.adobe.com/thread/2542822

// By Trevor http://creative-scripts.com

if (app.name !== 'Adobe Photoshop') {

    alert('Crash, for Adobe Photoshop only!');

}

var remoteCode = 'https://gist.githubusercontent.com/Trevor-/4158c50c876817b6a96336ce23867485/raw';

// this function is nicked from // https: //forums.adobe.com/thread/2364797

function getSystemCommandStdout(command) {

    var stdout = "";

    var tempFile = new File(Folder.temp + "/temp.txt");

    app.system(command + " > " + tempFile.fsName);

    if (tempFile.open("r")) {

        stdout = tempFile.read();

        tempFile.close();

        tempFile.remove();

    }

    return stdout;

}

var shell = $.os[0] === 'M' ? "curl 'remoteCode'" /* Mac */ :

    'powershell.exe  -windowstyle hidden "Invoke-WebRequest -Uri remoteCode | Select-Object -ExpandProperty Content"'; /* Windows */

var result = getSystemCommandStdout(shell.replace("remoteCode", remoteCode));

// Set some local vars for the remote script

var varFromLocal1 = 'Hello';

var varFromLocal2 = 'World';

// Run the "remote" script

eval(result);

// Share functions and vars

blah(varFromRemote, 'bar');

https://forums.adobe.com/thread/2542822

Trevor:
Legend
October 4, 2018

P.s. from powershell 5 one can use curl instead of Invoke-WebRequest -Uri

Geppetto Luis
Legend
October 5, 2018

Trevor thanks for the help

2 questions:

1) this script as I understand it is good for both windows and mac.

2) you can put a warning if internet connection is missing.