Take the 2-minute tour ×

Get your newb-shields up, I'm about to sprinkle you with some.
I'm trying to get Photoshop CS4 to open a folderful of JPEG images with AppScript+Python, which could be described like so in BASH:

for F in `ls ~/Desktop/test`; do
    open -a "Adobe Photoshop CS4" $F
    # proceed to mutilate the image appearance

I'm failing at the ls ~/Desktop/test stage. I'd really like to ask Finder to list a folder for me, and feed the result into Photoshop one at a time to process them.
A JavaScript equivalent with Adobe's ExtendScript bridge would be:

#target photoshop
var folder = Folder("~/Desktop/test");
var images = folder.getFiles();
    if (images[i] instanceof File && images[i].hidden == false) {
        var doc = app.open(images[i]);
        // do something to the image here

I can get me a document_file object with a horribly silly contraption like x = app('Finder').home.folders['Desktop']().folders['test']().items()[0], but that turns out to be a really silly object. Trying to app('Adobe Photoshop CS4').open(x) this object will throw an OSERROR: 1230, with a MESSAGE: File/Folder expected.

(Uh-oh, this document_file actually responds to URL(), so File.makewithurl(x.URL()) can be fed into open())

Ehm, having solved that, is there a way to actually do this by asking Finder for the list of files in a given folder, specified by a UNIX path?

share|improve this question
Why does this have an applescript tag? Typo? –  Philip Regan Dec 15 '09 at 20:40

1 Answer 1

up vote 3 down vote accepted

Photoshop's open command requires an alias object (or list of alias objects).

from appscript import *

folder = '/path/to/folder'

ps = app('Adobe Photoshop CS4')

for f in app('Finder').items[mactypes.Alias(folder)].files.get(resulttype=k.alias):
    # do stuff here...
share|improve this answer
Also, rather than using the Finder's scripting interface, OS X provides a hidden scriptable app, System Events.app, that includes a Disk-Folder-File suite with various properties. And, in some cases, it might just be simpler to use Python modules, i.e. os.listdir et al, to do file searching and then use appscript's Alias to form the proper reference. –  Ned Deily Dec 15 '09 at 19:39
Got it. Thanks has, thanks Ned. –  godDLL Jan 5 '10 at 3:30

Your Answer


