joonaspaakko / Photoshop-Illustrator-Script-Launcher-Using-Alfred

Launch PS and AI scripts using Alfred
16 stars 3 forks source link
alfred alfred-workflow illustrator-script-launcher photoshop-script-launcher

Photoshop & Illustrator Script Launcher (Alfred Workflow)

This workflow uses Alfred's built in File filter input and as such I haven't actually done much to put together this workflow. This is more just a wake-up call to anyone who isn't already doing this.

Usage

  1. Open Alfred (I use Ctrl+Space)
  2. Type in .ps or .ai and after that any following characters you type in does a fuzzy search for .js and .jsx files in the specified scopes.
  3. Pressing Enter will open the file and trigger the script.
    • Cmd+Enter will show the file in Finder.

Photoshop Example

Link to gif

Illustator Example

Link to gif

Default Scopes for the search

By default you need to put your .js and .jsx script files in there folders for the search to work:

The adobe scripts file filter searches scripts from anywhere inside ~/Dropbox/Adobe scripts/"

~ is equivalent to /Users/current_username/

You can change these folders by double clicking the file filter and then dragging new folders in the "Scope" tab. Delete old paths with backspace.

Why I think this is great way to launch scripts in PS and AI



Applescript

This is the script used in the Alfred workflow, though some things are changed so it works outside of Alfred.

set appName to "Adobe Photoshop"
set frontMostVar to false --Set true and the scripts are triggered only if the target app is active
set scriptFile to POSIX file "/Users/joonaspaakko/Documents/PS scripts.jsx"

tell application "System Events"
    set targetApp to application file of (first application process whose name contains appName)
    set appPath to path of targetApp
    set appName to name of targetApp
end tell

if frontMostVar is true then
    if application appName is frontmost then
        tell application "Finder"
            open scriptFile using appPath
        end tell
    end if
else
    tell application "Finder"
        open scriptFile using appPath
    end tell
end if

...and just for good measure, here's a more compact version without any bells and whistles. Most importantly in this script I'm using a static variable for the application path. Over the years I changed this workflow to get the app path automatically (like in the script above) because even in CC, the application path changes every year and it's really annoying to go around changing little things in workflows/scripts due to application changes.

set appPath to POSIX file "/Applications/Adobe Photoshop CC 2019/Adobe Photoshop CC 2019.app"
set scriptFile to POSIX file "/Users/joonaspaakko/Documents/PS scripts.jsx"

tell application "Finder"
    open scriptFile using appPath
end tell