Execute jsx script from a HTML file or js script - extendscript

Typically when you're writing a .jsx script to automate an Adobe product (like InDesign, Illustrator or Photoshop), you write, debug and execute the script from the ExtendScript IDE. Is it possible to bypass ExtendScript and run the script from an third program?
I have written script to automate some work of after effects. i have been running the script from ExtendScript IDE, but now i want user to give input arguments from a html form and then when he clicks submit button, i want to pass the user input to jsx script and then automatically run the script.
So basically I want to call jsx code from HTML or JavaScript code written in html file

That's tricky but it might be achieved if you don't consider that the html page will run the script but rather if the script is looking for some setup to appear thanks to the html page.
If you are on mac, you could write an applescript to monitor a folder and run the jsx file when needed.
If you can afford to have InDesign frozen, consider using the $.sleep() to have it checking a folder regularly. ANother approach is to rely on AS3 in order to make InDesign available when nothing happens in the html side.
Last but not least, These are grey areas because scripts have to be user executed in the desktop version of adobe software. What you are trying to achieve is more about server script handling. Given your budget, you may have a look at the InDesign server solution. No server solutions for Ai & Ps though.
Hope it helps,
Loic

Yes, it's doable, but amount of effort depends on your platform. And what I present is a client side solution, as Loic mentioned, if you are aiming for a remote user to hit your webpage on a server to do this, that doesn't really work. You're better off building a web service that does all this and then have HTML form invoke the web service.
For HTML form case you will need to be on Windows, and you would execute the JSX code, providing the needed arguments/parameters from the form using either VBScript or javascript (via Microsoft JScript) code encapsulated within a script tag in the HTML file. The VB/JS code can be within the script tags or pulled in from an external VBS/JS file via the script tag. Using this solution, your HTML file has to be named with extension ".hta" not ".htm" or ".html". And you may want to add some additional HTA element tags to the file.
See this for details: http://en.wikipedia.org/wiki/HTML_Application
The benefit of HTA is that the browser security restrictions against local file system are removed unlike traditional HTML pages, so you get additional access like being able to use VBScript (rather than just javascript for HTML pages) and use COM objects. The trick here is we will use the Adobe app's COM API to execute the JSX file.
If on Mac, you don't have a similar equivalent I believe. Therefore, your alternative option is to build a GUI similar to an HTML form but is actually a desktop app for Mac (e.g. wxWidgets, Qt, native Mac app, Java GUI app). With that GUI built, it can execute the JSX via Applescript, since many languages (Java, Python, etc.) should have an Applescript bridge interface. Worst case, you could shell execute an Applescript passing it the arguments that the Applescript then passes to the actual JSX script file.
As for how to pass arguments to JSX file and execute it outside of ExtendScript IDE, see this SO post:
Is it possible to execute JSX scripts from outside ExtendScript?
What I just mentioned about HTML form or a GUI app is simply interfacing that to the SO post solutions.

Related

Can node.js files have extensions other than ".js" to differentiate client and server code in a text editor?

I am working with a node.js backend, and often when I have multiple tabs open in my text editor it is difficult to tell which javascript files that I'm editing are on the server, and which are on the client.
Is it possible to change the extension of node.js files to something like ".node" so that it's easier to tell the difference?
I realize that you could achieve this if you use typescript for either the client or the server (.ts files), but I'd prefer to use standard javascript.
If this is impossible, is there another way to differentiate server and client javascript in a text editor like vscode?
You can restructurer your project as client/... server/... Then, you can hover on tab to view path and clarify it .
You should use :
Text Editor: VS Code
IDE : Web Storm

Can I use Python script to instead of chrome extension?

I used a chrome extension to download files on site, I want to know if I can create a Python Selenium script to do the same action like what in chrome extension? is it difficult?
While this is possible it's probably not a great practice...
I am not that comfortable with python or python-selenium;
However I do understand that if it's a web driver then there probably is a way to get this accomplished, look around for Python Selenium file download API on google.
Another aproach would be to make two apps that communicate with eachother - one made with html, css, javascript, php, etc to find the name of a file on a webpage.
Then message this to python (once again not sure how to do this, it's probably on google somewhere) once the file name on the website and website name are passed to python then put them together with something like this (javascript variable joining in context example):
...
var example = pageurl_as_variable + "/" + file_name_as_variable;
some_download_function_defined_else-where(example);
...
then obviously download this as file...
Once again this isn't the best practice and you can't make a chrome extension with python due to security reasons, but as described in the example above you could make an app-hybrid and then run this on the target users computer.
There are a lot of ways to do this with just basic HTML and potentially JavaScript so your better off looking into a way to do it that way...
Here's some links to point you in the right direction:
How can I download a file from a link in HTML?
How can I download a file on a click event using selenium?
(couldn't find anything on passing messages between the apps in my 5-seconds of googling).

Which languages do I need to learn to be able to program an extension

I am looking forward to program an extension for Google Chrome which runs in background and extracts information from a site. If a specific value of information equals my search parameters it should start performing some automated actions and then going back to the information-extraction loop.
Tl;DR
Language that can:
*automate web routines
*extract information
*running in background
Thanks in advance.
Using css, js and html as you do to make a website.
Look at this webpage: https://developer.chrome.com/extensions/getstarted

What general approach can I take to parse the contents of a website?

Say someone else has a website generated by JavaScript, so I can't go look at the source and read what should be on the screen. How can I grab the text on the screen so I can feed it into another program? Also, how can I write a program that automatically clicks on radio buttons, links, etc. that satisfy certain criteria?
You can write a web scraping tool in Perl or Python. Or, you can use existing tools and frameworks to achieve that.
Check out Scrapy, an open-source tool written in Python.
Take a look at Selenium too.
To parse dynamic content you could see the javascript source and get that same content the same way the webpage is getting it. (ie. replicating ajax calls and such)
If you want to submit data (not actually click on the elements) as if it were clicked/edited/selected you could also send a request containing the same data that the server is expecting by using some HTTP library, like CURL. See an example here.
If you need to handle content generated by script, then your first problem is to cause the script to execute. Further, the script will want to generate the content into a DOM. That means you need to have a DOM, and a script engine, and probably HTTP access to the Internet, and XML handling, etc.
If that sounds a lot like a web browser, then you're listening.
What you basically need is a web browser that you can control from a program. You'll need to be able to tell it to browse to a page, click buttons and links, etc., then you'll need to read back the resulting DOM.
Only then will you need to parse the page.
If you're in the Microsoft world, then you can use the WebBrowser control. There are several forms of this, and they all amount to the same thing: you can have Internet Explorer run inside of your program, and your program can control it.
I understand there are other browsers that can be controlled from a program, but since I don't know their details, I'll wait for someone else to tell us both.

How can I programmatically control a browser such as chrome in linux and execute javascript per each tab?

I have been given a task of toggling nearly 200 users' permissions in an admin. I have access to the database, and I'm sure I can do this in SQL but I'm curious to find out how to do it this way as well, plus I suspect it will be less work because I don't have to study the SQL that's going on and I know exactly what to do after I get access to the browser instance and know how to execute javascript programmatically in the context of the web page open.
I basically want to provide a list of urls which will open ( 195 ) and then execute javascript to toggle checkboxes, then submit the form.
As I stated, I want to use firefox or chrome and I'm on linux.
This is basically what greasemonkey does.
Or, if you can do it all while staying on the same page, you can also just type in arbitrary JS code by hand in the firebug console or its Chrome equivalent. This could work if combined with some iframe trickery.
If you use Chrome, it has built in support for user automation scripts: http://userscripts.wikidot.com/, http://www.chromium.org/developers/design-documents/user-scripts
I think a cleaner solution would be for you to figure out what is the url and the parameters to pass to do what you need. Then you can just use curl to make those requests.
I use CJS Chrome extension. I add a short script take loads a script from my localhost server and executes it. The executed script can also send results back to the server.

Resources