Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Load CEP from javascript file

Participant ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

I'm running a javascript file from apple script.

I would like to load CEP from the js file.  Here is what I'm attempting to do but it's not working.  I'm getting this error:

Adobe Illustrator got an error: Error 2: window is undefined.

First I load my js file in illustrator like so:

 

set jsFilePath to POSIX file "/Library/Application Support/Adobe/CEP/extensions/CEP_HTML_Test_Extension-9.0/js/autoRunTemplates.js"

tell application "Adobe Illustrator"
	launch
	do javascript jsFilePath
end tell

 

 Then I attempt to load the CEP file.  (Normally I load this in html).

 

function runScript() {
  #include './CSInterface.js'
}

runScript();

 

My goal is to run a javascript file from apple script to run some CEP type scripting in illustrator.

TOPICS
Scripting

Views

272

Likes

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

I don't understand what you're trying to do here. You cannot run CEP from scripting, you can only run scripting from CEP. Window is a global object that only exists in an HTML environment which is scoped to an existing CEP extension.

 

What is your goal? CSInterface does not work in scripting. It's a shim for an HTML environment to have aliases to communicate with the app. What are you trying to use CEP for, instead of telling us you're trying to use CEP?

Likes

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
Participant ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

Ok it makes complete sense.  I need to run a CEP task from Apple script.  My idea was to run a javascript file and then execute the CEP from the js file.  How can I launch the CEP html from an apple script command?

Likes

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

What CEP task? This may be an XY problem. I'm asking what you're trying to accomplish but you only tell me what your proposed solution is, not saying the intent of that solution or the original problem.

Likes

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
Participant ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

In CEP i have different tasks that I run using the html CEP. In example
setting up some illustrator files. I need to set this on a timer to run
every night. My solution was to do this via apple script and then have it
automate the CEP tasks. This is why I thought running the CEP through
javascript would work. The exact tasks vary but ultimately it's clicking a
button on the CEP that runs the CEP scripts.

Likes

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

Personally I'd do that through a macro service like AutoHotKey (Windows) or SharpKeys/Alfred (Mac). I don't know anything about Applescript so I don't know if it's viable. CEP is scoped to the application and cannot open itself per se (unless done via command line, another CEP instance from some other app, or some other external source). As far as CEP is concerned, you could just open Illustrator with a CEP extension having StartOn events in the manifest:

<DispatchInfoList>
    <Extension Id="someExtension">
        <DispatchInfo>
            <Lifecycle>
                <StartOn>
                    <Event>applicationActivate</Event> 
                </StartOn>
            </Lifecycle>

 

Then every time you open Illustrator, your CEP extension will automatically launch. So if you can open AI through Applescript at some given time every night, your CEP panel should subsequently open as well, then you'd use evalScript to interact with AI to do whatever it is you're trying to do, wait for some response, then have the application close itself. Otherwise you could just constantly leave Illustrator open and have a setInterval running in CEP that checks the Date to programmatically run something at a given time once a day but that's not a very good approach because it's dependent on the application being open and responsive at all given times.

 

As far as technical questions go, the reason I bring up the X/Y Problem is because from my experience, you are always going to have more success getting a response with the structure "I want to do X, so I've tried Y, but I'm having with trouble with Y". In this post, your structure is "I'm trying Y but I'm having trouble with Y". As far as we know, you might not need Y at all. Your answer might be to use Z, you might only think you need Y when in reality that's only because you don't know any better, but without knowing what Problem X is (and what you're trying to accomplish), questions often seem too vague to answer and people gloss over them because you're going to have to spend another 2 - 3 replies just to get to what Problem X was in the first place. Ever since I started formatting every question like this, I've always gotten quick, concise, and relevant responses and it's one of the biggest growths for me as a programmer because I have help in solving my problems much more often and easily.

Likes

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
Participant ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

LATEST

Excellent info, thank you so much!

Likes

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