• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

VBScript to call JavaScript

Engaged ,
Feb 08, 2017 Feb 08, 2017

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?

TOPICS
Actions and scripting

Views

2.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Feb 15, 2017 Feb 15, 2017

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 08, 2017 Feb 08, 2017

Copy link to clipboard

Copied

Sorry.jpg

Sorry.

You always asking but never give credits to your helper.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 09, 2017 Feb 09, 2017

Copy link to clipboard

Copied

Probably because that's not been pointed out to me

Whooops! My bad

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 13, 2017 Feb 13, 2017

Copy link to clipboard

Copied

You don't need VBS for this. JS has Prompt.

13-02-2017 13-46-51.png

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;

    }

}

13-02-2017 13-50-06.png

— Kas

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 14, 2017 Feb 14, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 15, 2017 Feb 15, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

LATEST

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

15-02-2017 14-23-20.png

CC 2017

15-02-2017 14-20-10.png

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines