Run Javascripts

Hello,

          I have a few J[b]avascripts[/b] for automation of Photoshop and Illustrator  for this I use Applescript to run the [b]Javascripts[/b] on MAC, I just know how to do it this way and would like to know if there way to run AppleScripts something like ExecuteJavascript or something equivalent ?

We have plugin classes like AppleScriptMBS or NSAppleScriptMBS.

[quote=100242:@Paulo Vargas]Hello,

          I have a few J[b]avascripts[/b] for automation of Photoshop and Illustrator  for this I use Applescript to run the [b]Javascripts[/b] on MAC, I just know how to do it this way and would like to know if there way to run AppleScripts something like ExecuteJavascript or something equivalent ?[/quote]

This link to a s short tutorial I had posted in the ‘Yosemite comes with JavaScript’ may help you :
http://www.mikebobiney.com/2012/06/12/getting-started-with-ui-automation-in-xcode-4/

Of course when something goes wrong edit does not work :confused:

http://www.mikebobiney.com/2012/06/12/getting-started-with-ui-automation-in-xcode-4/

OK. The tutorial in question above is for iOS. Searching for Mac OS X did not pan yet :frowning:

Today, Edit simply does not work in this forum :confused:

I have finally found more.

Yosemite comes indeed with an application called Script editor which supports both AppleScript and JavaScript for UI automation.

I just found out that back in the 10.4 era, Script Editor came with OS X and already supported JavaScript. See
http://blog.latenightsw.com/?p=6

Now, what happened that made Apple dump JavaScript compatibility, and replace Script Editor by AppleScript Editor until Mavericks will probably remain a mystery.

So the fact is I found no simple way to use Javascript for UI automation in the current Mac OS X system. Looks like you have to wait for Yosemite.

Tks Michel Bujardet I will look all that sent me to see if I can get something that fits my projects.

To make it clear I need to place a JavaScript code straight into my Xojo and make it run with one clic in a Button Action, is it possible?

I put down a Javascript I have and I can only run via AppleScript:

[quote]var myDocument = app.activeDocument;
var idDstt = charIDToTypeID( “Dstt” );
executeAction( idDstt, undefined, DialogModes.NO);
[/quote]

This wasn’t the case with “old style” Applescript and won’t be the case for JavaScript Applescript. As before you need to either embed the script or run it with MBS.

Beatrix, how do you proceed then ? Care to share sample code ? TIA

As soon as I have some time I’ll install Yosemite and fire up the AppleScript editor and play around. Then I’ll put the result in my MBS AppleScript wrapper from http://www.mothsoftware.com/content/xojo/. But at the moment I’m busy with finishing the release of my software.

I have already gone to your web site and downloaded runAS.

Thank you and good luck for your release :slight_smile:

Thanks for now

Yosemite comes with the Script Editor which supports both AppleScript and JavaScript. It is identical to Mavericks AppleScript Editor, except it offers the choice between AppleScript and JavaScript. From what I understand, recording cannot work in JavaScript.

Yosemite comes indeed with JavaScript installed in the OSA system. It shows in the Terminal as :

$ osalang AppleScript JavaScript Generic Scripting System

The same command in Mavericks shows only AppleScript and Generic Scripting System.

The shell command osascript also supports JavaScript for automation. I have taken from the page https://developer.apple.com/library/prerelease/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/index.html#/apple_ref/doc/uid/TP40014508 the short example which scripts Notes, typed it into the Script Editor to create openNotes.applescript and ran this in Terminal :

$ osascript -l JavaScript openNotes.applescript openNotes.applescript:139:212: execution error: Error on line 6: Error: Access for assistive devices is disabled. (-1)

The script opens the application fine, but the error is due to the fact that I did not allow Terminal to generate click events. This is set in the Security & Privacy Preferences/Privacy as “Allow the apps below to control your computer”. It was already the case in Mavericks for AppleScript and certain GUI scripting features.

The same script can be used in Script Editor format, or in plain text.

It is important to know that Mavericks and previous versions since Leopard (I do not have anything older) do not have JavaScript for automation installed.

[quote=100500:@Paulo Vargas]To make it clear I need to place a JavaScript code straight into my Xojo and make it run with one clic in a Button Action, is it possible?

I put down a Javascript I have and I can only run via AppleScript:[/quote]

There might be some confusion here.

You don’t run your javascript with applescript in Yosemite. You run your javascript just as you’d run your applescript. They’re both for the same thing, not one for the other.

If you want to port your applescripts to yosemite’s javascript, you need to rewrite them to do the same thing as your current applescripts do. This is a straight up language translation from the code you currently have to the new code you’ll arrive at.

https://developer.apple.com/library/prerelease/mac/releasenotes/interapplicationcommunication/rn-javascriptforautomation/index.html

https://developer.apple.com/videos/wwdc/2014/ (search for JavaScript for Automation)

Maybe It may be easier than I’m thinking, let’s hope the final version of Yosemith to see how it run, because today I use an Applescript to run the Javascripts but it can get easier Tanks.

I’ve been thinking, would not like to run a Javascript like below within HTMLVIEWER in a Desktop project?

Remembering that this JavaScript written for Photoshop.

[quote]var myDocument = app.activeDocument;
var idDstt = charIDToTypeID( “Dstt” );
executeAction( idDstt, undefined, DialogModes.NO);
[/quote]

[quote=100967:@Paulo Vargas]I’ve been thinking, would not like to run a Javascript like below within HTMLVIEWER in a Desktop project?

Remembering that this JavaScript written for Photoshop.[/quote]

The HTMLViewer does JavaScript on the DOM content, not on the scriptable applications.

Adobe applications use JavaScript internally, so you probably do it now as below, right ?

tell application "Adobe Photoshop" activate do javascript "var myDocument = app.activeDocument;" do JavaScript "var idDstt = charIDToTypeID( "Dstt" );" do JavaScript "executeAction( idDstt, undefined, DialogModes.NO);" end tell

The same code will run directly with JavaScript for applications, you simply will need to start with

Photoshop = Application('Adobe Photoshop') Photoshop.activate()

Or something like that. I have not yet installed Photoshop Elements I use, under Yosemite.

Yes I do this with AppleScripts!

I’ll try your other approach and then give feedback, thanks

[quote=100982:@Paulo Vargas]Yes I do this with AppleScripts!

I’ll try your other approach and then give feedback, thanks[/quote]

I picked that up directly from the Apple JavaScript for application page linked by Oliver at the start of this thread. It works fine in Script Editor from Yosemite.