Sublime Text

Sublime Text 2 and 3 ExtendScript Photoshop package (Updated)

Davide Barranca —  — 15 Comments

This post contains a Sublime Text 2 custom build package that lets you run ExtendScript code targeting Adobe Photoshop. I’ve coded it applying few tweaks and customization to an existing package made by Sébastien Lavoie for After Effects scripting. 

What is that for?

When you code Photoshop scripting, chances are that you do it with the ExtendScript ToolKit (aka ESTK). While this Adobe provided piece of software has some unique features that make it very efficient while debugging and looking for DOM documentation, as an editor it really sucks. I’m sorry about that, but compared to other modern editors it’s barely usable.

Sublime Text 2, (and the 3 beta) conversely, are an amazing editor with tons of features and plugins. Yet so far the only workflow for Photoshop scripters was to code ExtendScript (which is a superset of Javascript) in Sublime Text, then copy and paste it to ESTK and run the script from ESTK.

This custom build package lets you run ExtendScript code targeting Photoshop in Sublime Text 2 and 3. Type ⌘B (or ctrl+B) and your code is being executed in the host app!

UPDATE (September 2016)

I’ve tweaked the Package described in this article, originally written in 2013. Important news:

  • The code is now hosted and maintained in a GitHub repository that you can find here.
  • It’s been updated to support Photoshop CC 2015.5.
  • Simplified the code a lot

Please refer to the GitHub repository for updated instruction – I keep the rest of the article as a document of the past.

Installation

Download ExtendScript-PS (V2.0 – April 2014, defaults to Photoshop CC, customizable for CS6), the Sublime Text 2 build package for Photoshop ExtendScript. Unzip it and move the ExtendScript-PS folder in:

[OSX] ~/Library/Application Support/Sublime Text 2/Packages

[Win] ~\AppData\Roaming\Sublime Text 2\Packages

If you’re unsure where the Packages are located on your system, find them from the Sublime Text menu: Preferences – Browse Packages… Do an app restart, just in case!

How to use it

Write your ExtendScript as usual, and save the JSX file you’re working on (if you don’t, it won’t work).

Build SystemMake sure the Tools – Build System – ExtendScript_PS is checked, then build the script with ⌘B (Mac), ctrl+B (PC) or the Tools – Build menu item.

As you build it the JSX script is copied to the Photoshop’s Presets/Scripts/ folder, a confirmation message appears on the Sublime Text 2 console, then it’s run in the host application.

Depending on your platform and/or PS version, a couple of tweaks may be needed in order to make the it run in your system: please open the ExtendScript-PS folder (in the Sublime Text 2 packages) and read along.

Mac Hacks

The build package, as it is, works on Photoshop CC, CS6 (and possibly CS5 too).
In the script.scpt file make sure you are targeting the correct Photoshop version:

Moreover (see line 10) you can uncomment show debugger to activate ExtendScript Toolkit: available options are either before running, neveron runtime error.

Windows Hacks

The build package, as it is, works on Photoshop CC (64 bit). I did test it for CS6 on a virtualized Windows 7, so feedback from actual PC users is welcome. Check that the build.bat file contains information that matches your system in these lines:

Particularly, set the correct:

  • Photoshop version (CS5, CS6, CC…) which has to match the application’s folder name.
  • Photoshop folder (in the comments there’s the default 32 bit path if you need it) – change it accordingly if PS has been installed in a custom disk/directory.

Credits

I’ve cloned from GitHub the original Adobe After Effects package for Sublime Text 2 made by Sébastien Lavoie – which I have tweaked to fit Photoshop’s scripting needs (Version 1 in May 2013, Version 2 in April 2014).

I’m a poor hacker, so if the package doesn’t work properly it’s my fault only. Feedback is welcome as usual, happy coding!

Print Friendly
Share

15 responses to Sublime Text 2 and 3 ExtendScript Photoshop package (Updated)

  1. What would it take to do the same thing for InDesign scripts?

    • I’m afraid Rick I’m not into InDesign scripting! If someone wants to chime in in my place…

    • replace run.scpt with:
      ===================================
      on run arg

      set theFile to arg’s item 1

      tell application “Adobe InDesign CC 2014”
      activate
      do script theFile language javascript
      end tell
      end run
      ===============================

  2. Also I found easy just to open jsx file in sublime and ExtendedScript toolkit at the same time. When I save file in sublime it is automatically updated in EXS

  3. Hi Davide,
    I have tried it in sublime but get the following error, although I did all you said in the tutorial and I made sure the paths were correct – did I perhaps miss a step? How does it recognize photoshop.exe as an external application from the .bat?

    1 file(s) copied.
    ‘photoshop.exe’ is not recognized as an internal or external command,
    operable program or batch file.
    “Successfully compiled 3x3gifmaker.jsx to \3x3gifmaker.jsx”;
    [Finished in 0.1s]

  4. Is this the Extended Script Photo Package compatible with Photoshop CC?
    I was not able to find the script.scpt file.

    I try updating the build.sh and run.scpt files but sublime text does not save the script files in the Application/Adobe Photoshop CC/Presets/Scripts location.

    ////////////////////////////////////////////////
    build.sh edit :
    # Your CS version
    version=”CC”;

    # Adobe Photoshop folder location
    base_path=”Applications”;

    # Full path
    full_path=”/${base_path}/Adobe Photoshop CC ${version}/Presets/Scripts”;

    ////////////////////////////////////////////////
    run.scpt edit:
    on run arg

    set fileName to arg’s item 1
    set psVersion to “CC”
    set basePath to “Applications”
    set theFile to POSIX path of (basePath & “:Adobe Photoshop CC ” & psVersion & “:Presets:Scripts:” & fileName)

    open for access theFile
    set fileContents to (read theFile)
    close access theFile

    tell application “Adobe Photoshop CC”
    do javascript fileContents (* show debugger before running / never / on runtime error *)
    activate
    end tell

    end run

  5. Thanks for this update Davide!
    I was also doing the – workInRealEditor>Copy>PasteIntoESTK – method whenever I was debugging my JSX scripts, I was excited to read about this, and thought I’d take some time today to pickup Sublime Text. Nice! Everything worked like a charm on my Mac, BUT I did run into the same errors as Paul did back in April of 2013 on my PC (win7 64) :

    “1 file(s) copied.
    ‘photoshop.exe’ is not recognized as an internal or external command”

    A quick solution was to add the version of photoshop I wished to call with the “photoshop.exe” command to my system PATH environment variable. …. ;C:\Program Files\Adobe\Adobe Photoshop CC (64 Bit)\
    And that did the trick. This means I’ll have to update this Env Variable if I want to use a different PS version, but its a 2 second change, so not a big deal.

    I’m sure there is a better way to do this, and if anyone out reading this has suggestions, I’m all ears! But as I hadn’t seen anything posted here in reply to Paul, I thought I’d let folks know\my hack that solved this issue.

    Thanks again!

  6. Thank you very much for the workaround Sandra!
    Naively, I thought that the build.bat should already provide the correct path, I’m surely missing something here but I’m not on Windows myself and I’m short of ideas.
    Let’s see if somebody can suggest a permanent fix. In the meantime kudos for the help!!

  7. I have just tried this but when I try to build, the following error is showing in the console of SublimeText 2

    /Users/ianbarber/Library/Application Support/Sublime Text 2/Packages/ExtendScript-PS/run.scpt:92:104: execution error: End of file error. (-39)
    [Finished in 1.7s with exit code 1]

    Any help appreciated

  8. I’m having trouble on -some- of my jsx files. No matter the content or file location. I even tried copying the whole contents from one file that works into one that doesn’t and it still bugs out.

    Any idea what might be causing it?

    /Sublime Text 2/Packages/ExtendScript-PS/run.scpt:92:104: execution error: End of file error. (-39)

    • I fixed it by setting the read file to utf-8:
      set fileContents to (read theFile as «class utf8»)

      • Additionally it would break if there was a space in the file argument. I fixed it by adding quotes around $file in ExtendScript_PS.sublime-build:
        “osascript ‘${packages}/ExtendScript-PS/run.scpt’ ‘$file'”

        Now everything works like a charm! Cheers!

  9. Hi Davide,

    As a JS newbie and having fallen for Sublime I would love to break away from ESTK for my .jsx coding but I’m having trouble running the build.

    I get the error;

    ‘build.bat’ is not recognized as an internal or external command,
    operable program or batch file.

    I’ve installed the package correctly in the Sublime packages folder and I’m running Sublime 2 as admin. but this run error on CTRL-B still occurs. Any ideas you may have would be great.

    Kind regards,
    Jen.

  10. Davide,
    I have installed the ExtendedScripts-PS package in Sublime Text 3 and can not make it work after updating the application version to Adobe Photoshop CC 2015 in the run.scpt file.
    I am running an admin account in OSX 10.11 EL Capitan in a MBP.

    Any suggestions how to make it work?

Leave a Reply

Text formatting is available via select .

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url=""> 

*
*