Copy link to clipboard
Copied
See if you guys can help me:
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.
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?
Check out this thread.. Calling an action in extendscript toolkit
Copy link to clipboard
Copied
Sorry.
You always asking but never give credits to your helper.
Copy link to clipboard
Copied
Probably because that's not been pointed out to me
Whooops! My bad
Copy link to clipboard
Copied
You don't need VBS for this. JS has Prompt.
main();
function main() {
var askName = prompt("Enter name:", "", "My script");
// if the user hits 'Cancet', it returns null, otherwise the value of the text edit field
if (askName != null) {
// 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;
}
}
— Kas
Copy link to clipboard
Copied
Kas,
I know about JavaScript UI but... I've been having the same problems as this guy: Script won't create UI as window does not have a constructor. The problem is erratic and hard to pin down. I do NOT want to have to delete PS prefs each time.
So I was wondering if it was possible to get VBS UI to call the JavaScript. - Although I might end up doing something in HTML instead
Copy link to clipboard
Copied
Unlike InDesign, Photoshop doesn't have the 'doScript' method so, of the top of my head, my answer is no, it's impossible. Maybe there's a workaround but I don't know about it.
In my opinion, the easiest approach, in this case, would be to translate the script from JS to VBA.
— Kas
Copy link to clipboard
Copied
Check out this thread.. Calling an action in extendscript toolkit
Copy link to clipboard
Copied
I looked for it only in the JS reference: obviously it wasn't there. It is in the VBS reference (last time wrote in VB for Photoshop somewhere in 2004 -- that's why I didn't look here) so theoretically it should work but, for some reason, VBS-files don't appear in my scripts menu (tested in CC 2015 and 17). Also, they're unavailable via 'Browse' menu: it allows to choose only JS.
CC 2015
CC 2017
Here they give a contradictory information:
First they say: "In Windows, you can use scripting languages that support COM automation, such as VB Script."
A few lines below: "Choose File > Scripts and then select the script from the list. The scripts list includes all the script files saved with a .js or .jsx extension and saved in the Photoshop CS5/Presets/Scripts folder. To run a script saved in another location, choose File > Scripts > Browse and navigate to the script."
— Kas