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

How to make Applescript open AI then open file then run ExtendScript then close?

Participant ,
Mar 20, 2015 Mar 20, 2015

Here's the sample Applescript code I came up with using the scripting guide/reference for CS6 and also doing some online searches:

tell application "Adobe Illustrator"

    activate

    delay 10

    set pfilepath to "/Users/username/Documents/Temp/someFile.ai"

    set pfile to POSIX file pfilepath

    open pfile as alias without options

    delay 10

    do javascript "#include '/Users/username/Documents/Temp/someScript.jsx'"

    delay 1

    quit

end tell

I just want to open the app (sample here for AI but also nice to do same for Photoshop), open a file, then run ExtendScript file against it, then close after processing. With this sample script, all that works is the app launches. No file opened, no script ran, app doesn't close at end. I see no errors pop up nor anything show up in command prompt.

The sample ExtendScript just triggers an alert popup message for testing

Also to note, the Applescript snippet is executed from Python but I believe where/how it's executed shouldn't matter (except maybe where the error messages might show up). Although in worse case, I'll debug/run through the AppleScript editor.

Any tips on what's wrong here? Or does it look technically correct?

TOPICS
Scripting
3.2K
Translate
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

correct answers 1 Correct answer

Participant , Mar 25, 2015 Mar 25, 2015
Translate
Adobe
Participant ,
Mar 25, 2015 Mar 25, 2015
Translate
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
Valorous Hero ,
Mar 26, 2015 Mar 26, 2015

Are you  writing the cross-platform Python application?

Translate
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 ,
Mar 26, 2015 Mar 26, 2015

Yes, indeed. On Mac, Python executes the Applescript. On Windows, it invokes the Adobe COM API (in Python rather than the default suggested VBScript). Supposed to be a generic command line script launcher for executing javascript ExtendScripts w/o manually opening/dealing w/ the Adobe apps as well as being able to open a document before executing script as needed for scripts that expect to work against active documents.

Translate
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
Valorous Hero ,
Mar 26, 2015 Mar 26, 2015

Good stuff, do you have any documentation you can tell me which is for preferably, beginners, that accomplishes a similar setup using the Python? And, is this because some users use a Mac and others use the PC for Adobe apps within the organization?

Translate
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 ,
Mar 26, 2015 Mar 26, 2015
LATEST

No, I don't have specific documentation, but you can put together such for Python from bits & pieces here & there. And yes, I made it cross-platform to anticipate Adobe users on both Mac & PC, for which there currently are, though for what we're doing skews towards Windows for now.

For the COM API, follow the VBScript reference and code samples. Just convert the method calls to Python COM. There will be slight syntax differences sometimes (e.g. add "()" to method call for VBScritp subroutines that don't need them, etc.). The scripting guide link below should have code samples for VBScript.

http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2014/Illustrator%20Scriptin...

http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2014/Illustrator%20Scriptin...

For example of Python COM, you can search online, or look at AutoItDriverServer/server.py at master · daluu/AutoItDriverServer · GitHub, which may be bit much/complex for you? For Python COM, you either need ActivePython or regular Python plus Python for Windows Extensions (e.g. pywin32).

For Applescript and Python, this post might be useful: osx - Calling AppleScript from Python without using osascript or appscript? - Stack Overflow

for the rest of the the cross-platform support, it's just generic python to parse command line arguments, etc. You may want to query what platform the script is running under using some standard Python modules (os, system). An example can be found in AutoPyDriverServer/server.py at master · daluu/AutoPyDriverServer · GitHub

Hope that helps.

Translate
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