0

Going out on a limb here. Is there a way for a Photoshop VBScript to call a JavaScript file?

Or at least pass some user input (variable or return from function) from one script to another.

My reason for this? I've been having similar issues asked in this question and considered a VBScript UI to drive a photoshop-script. Re-writing the existing jsx into VBS isn't really an option.

Here's what I have. This simple VBScript asks for the user to type in their name which is then created as text in the second script.

VBScript

' Ask User for input
Dim appRef
Set appRef = CreateObject( "Photoshop.Application" )

Dim askName : askName = InputBox("Enter name: ")

JavaScript

// create a document to work with
var docRef = app.documents.add(200, 100, 72, "Hello");

// Create a new art layer containing text
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;

// Set the contents of the text layer.
var textItemRef = artLayerRef.textItem
textItemRef.contents = "Hello " + askName

What do I need to connect the two up?

1 Answer 1

3
+50

I have no experience in scripting with Photoshop, did some research.

The following code has been tested with Adobe Photoshop® CS6.

PsJavaScriptExecutionMode enum constants are extracted from scriptingsupport.8li (Adobe Photoshop CS6 Object Library) by using Microsoft OLE/COM Object Viewer.

VBScript:

'PsJavaScriptExecutionMode Enums
Const psNeverShowDebugger = 1, psDebuggerOnError = 2, psBeforeRunning = 3

Dim appRef
Set appRef = CreateObject("Photoshop.Application")

Dim askName
    askName = InputBox("Enter name: ")

appRef.DoJavaScriptFile "C:\scripts\myPSscript.jsx", Array(askName), psNeverShowDebugger

JavaScript (myPSscript.jsx):

// create a document to work with
var docRef = app.documents.add(200, 100, 72, "Hello");

// Create a new art layer containing text
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;

// Set the contents of the text layer.
var textItemRef = artLayerRef.textItem
var askName = arguments[0]; // first argument passed from VBScript
textItemRef.contents = "Hello " + askName;

Hope it helps.


Adobe® Creative Suite® 5 Photoshop® Scripting Guide

Sign up to request clarification or add additional context in comments.

4 Comments

It worked! - just as long as you don't have the VBscript & PScript called the same ie test.vbs & test,jsx
@GhoulFool Sorry I couldn't understand. What was the question then?
No question. It's all good :) The code worked. But the first time I tried I named both files the same C:\scripts\myPSscript.jsx & C:\scripts\myPSscript.vbs and that came up with an error. By renaming the VBS to C:\scripts\myscript.vbs Does that make sense now?
@GhoulFool It's important to know what the error message says. I couldn't reproduce the issue. It was probably a file not found error due to a typo, I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.