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

How to pass arguments from command line to the .jsx

New Here ,
Nov 04, 2013 Nov 04, 2013

Copy link to clipboard

Copied

Hi, I have a .jsx file that does some scripting with photoshop. I would like to be able to call that script from the command line and pass some arguments. I have been going off of the forum at http://support.muse.adobe.com/thread/290023, mainly the last post. Here it is ...

command line example : runjavascript.vbs c:\mydirectory\test.jsx arg0 arg1 arg2 arg3


=====start runjavascript.vbs ===============

Set vbsArguments = WScript.Arguments


If vbsArguments.Length = 0 Then

WScript.Echo "Argument(0) is `your script to execute"

WScript.Echo "Arguments(0+n) are passed to your script as argument(0) to argument(n-1)"

Else

ReDim jsxArguments(vbsArguments.length-2)


for i = 1 to vbsArguments.length - 1

jsxArguments(i-1) = vbsArguments(i)

Next


Set photoshop = CreateObject( "Photoshop.Application" )

photoshop.BringToFront


'DoJavaScript has 3 parameters

' syntax DoJavaScript(arg[0], arg[1], arg[2]]

'arg[0] == javascript file to execute, full pathname

'arg[1] == an array of arguments to past to the javascript

'arg[2] == AiJavaScriptExecutionMode: aiNeverShowDebugger = 1,, aiDebuggerOnError = 2 aiBeforeRunning = 3

' only use 1

Call photoshop.DoJavaScriptFile( vbsArguments(0), jsxArguments, 1)

End IF


=====end runjavascript.vbs ===============


=======start test.jsx ====================


#target photoshop


for( n = 0 ; n < arguments.length; n++ ){

alert("argument("+ n+")= " + arguments);

}

=======end test.jsx ====================

In summary, it calls a VBScript from the command line and passing args to the VBScript where it will run the .jsx and pass along the args to the .jsx. This is all seems to work, except that the args never make it from the command line into the .jsx and I'm having trouble narrowing down why.

I know the args are getting into the VBScript from the command line because I can successfully print them out using WScript.Echo. The VBScript then takes the args and makes a new array called jsxArguments which just holds the arguments that are to be passed on to the .jsx as the second argument in the DoJavaScriptFile().

I cannot tell if the jsxArguments is correct or not. I added an isobject(jsxArguments) check in the VBScript which fails, but if I do a WScript.Echo jsxArguments(0) it will correctly print out the contents of the array at that position.

I know that the args are not getting into the .jsx because I added a line alert(arguments.length) which prints out 0.

Any help would be greatly appreciated. Thanks.

TOPICS
Actions and scripting

Views

2.2K

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
Adobe
Guru ,
Nov 04, 2013 Nov 04, 2013

Copy link to clipboard

Copied

I don't use VBS so this is just a guess based on what I have read in this forum. I think when you are passing an 'array' to javascript it needs to be a variant data type. My guess your arguments are not making it to the javascript because it it the wrong data type.

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
New Here ,
Nov 04, 2013 Nov 04, 2013

Copy link to clipboard

Copied

LATEST

Good idea. So how do I make it the right data type?

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