Reputation: 6949
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?
Upvotes: 0
Views: 1652
Reputation: 16950
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
Upvotes: 3