Converting from .jsx to .sscript for InDesign Script

Post Reply
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Converting from .jsx to .sscript for InDesign Script

Post by jugganaut »

I could use some help "converting" a native adobe ExtendScript written script to use as a native Switch script. I'm a little vague on the built in functions to get jobs in and out of a script within switch...

My current script is for InDesign, just imports a folder of images and loops through each image to place on a page, exports as a PDF. Where's a good place to start? For instance, instead of

Code: Select all

$doc
variable, am I using

Code: Select all

var jobPath = job.getPath();
? What I've tried doesn't yield much results...

This is all javascript btw...
loicaigon
Member
Posts: 147
Joined: Wed Jul 10, 2013 10:22 am

Re: Converting from .jsx to .sscript for InDesign Script

Post by loicaigon »

Hi,

Your request is a little bit strange to me. Javascript by nature is based on a Object Model. The fact that you can script InDesign with JavaScript stands on the specific InDesign object Model. When you are scripting Switch, you are using the specific Enfocus Switch Object Model.

So if you intend to drive InDesign with a javascript sscript file, I am pretty certain you can't. However, if you are really willing to drive InDesign with a sscript, I guess you should rather use a combination of VB and AppleScript inside a sscript. These languages can be run in a higher scope than Javascript (i.e. the system). That way you can execute VB/APS InDesign code inside a sscript.

On top of that, you could use a single line of VB/APS which consists in executing javascript code inside InDesign.
#VB See : http://www.adobe.com/content/dam/Adobe/ ... torial.pdf
myInDesign.DoScript(myJavaScriptString, idScriptLanguage.idJavascript)

*APS See: http://wwwimages.adobe.com/content/dam/ ... ide_AS.pdf
do script myJavaScript language javascript with arguments myParameters

Then all you have to do is to pass the parameters you need in your javascript string.

So one script could be :

sscript say in APS

Code: Select all

-- Is invoked each time a new job arrives in one of the input folders for the flow element.
-- The newly arrived job is passed as the second parameter.
on jobarrived( s, j )
	
	--Retrieving the job path
	tell application "Switch_Service"
		set theJobPath to path of j
		set theJobPath to POSIX path of theJobPath
	end tell

	--Your js code as string
	set js to "app.open( File(\""&theJobPath&"\") ); alert(\"open !\"); app.activeDocument.close(SaveOptions.NO);"
	
	--Calling InDesign to run the js code
	tell application "Adobe InDesign CC 2014"
		do script js language javascript
	end tell
	
end jobarrived
If you need the VB side, drop an eye onto the documentation.

FWIW,

Loic Aigon
http://www.ozalto.com
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Re: Converting from .jsx to .sscript for InDesign Script

Post by jugganaut »

i keep no secret of my ineptitude of switch and programming, and while yes, you cannot control system functions with javascript (prior to yosemite anyway), can you not use a .sscript file as your script for a configurator script instead of a .jsx? As to take advantage of the built in switch functions? Sort of the best of both worlds... Or have I been misinformed?
loicaigon
Member
Posts: 147
Joined: Wed Jul 10, 2013 10:22 am

Re: Converting from .jsx to .sscript for InDesign Script

Post by loicaigon »

Hi,

Maybe I am being confused here but if you want to create your own configurator you indeed have to create a sscript file which can use JavaScript but which is not a JS file strictly speaking. A sscript is more of a container which can include or not JavaScript Code to be executed in the Switch context.

So I don't think you can just turn your InDesign js code into a sscript because of the specificity of the Switch Object Model.

Does this make sense ?

Loic
http://www.ozalto.com
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Re: Converting from .jsx to .sscript for InDesign Script

Post by jugganaut »

Yes, I got it. So are the "arguments" the only way to get Switch variables into a .jsx script for use?
loicaigon
Member
Posts: 147
Joined: Wed Jul 10, 2013 10:22 am

Re: Converting from .jsx to .sscript for InDesign Script

Post by loicaigon »

Yes indeed. But it would be the same in a sscript except that you would retrieve properties of the job, not arguments.
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Re: Converting from .jsx to .sscript for InDesign Script

Post by jugganaut »

So, for instance, I could retrieve private data from within the jsx script, just as I would in a sscript?
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: Converting from .jsx to .sscript for InDesign Script

Post by freddyp »

Javascript in Switch (sscript) and Javascript in Indesign live in different environments. You cannot access Switch functions in Indesign and the other way around. Period.

I also would like to comment that I see no added value in converting from .jsx to .sscript. The only thing that makes sense is to modify a jsx that is used in Indesign to comply with some conventions for use in the Indesign configurator. Please refer to the "Javascript for applications" section in the Switch documentation for that. There are a number of variable names that you MUST use and it explains how to pass Switch information to the Indesign script through the arguments.

Freddy
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Re: Converting from .jsx to .sscript for InDesign Script

Post by jugganaut »

Freddy,

Thanks - the docs can be a little on the light side sometimes and I always work better from example, which I have a few. The only benefit to using the sscript file would just be the ability to bring in more data, as you are limited to just 5 or 6 arguments. But i think by creating an array to bring data in I can get around that limitation...

Thanks for the info and helping me understand scripting a little better...
loicaigon
Member
Posts: 147
Joined: Wed Jul 10, 2013 10:22 am

Re: Converting from .jsx to .sscript for InDesign Script

Post by loicaigon »

Hi,

I agree that one may feel limited with these 5/6 arguments while calling a jsx script in the properties pane. However, you can definitively pass a rich data object as an argument and initiate it in the indesign scripting context. Let me explain.

While passing a xml string as an argument, it's easy to instantiate a XML object within InDesign Scriptengine from this string and then have access to a myriad of arguments. The same would stand for json strings.

Besides it's likely I would prefer XML or JSON to access an argument rather than having to remember in which position the argument I need is.

<arg firstname="John" surname="aigon" position="consultant"/>
Image

Then the script :

Code: Select all

function main() {
	
	var x = XML ( String ( $arg1 ) );
	if ( !( x instanceof XML) ) return;
	
	alert( "First name:"+x.@firstname+"\r"+
			"Surname:"+x.@surname+"\r"+
			"Position:"+x.@position );
}

main();
Then finally the flow being flowed and the script executed :
Image

FWIW,

Loic
http://www.ozalto.com
Post Reply