Open selected files in photoshop

I’m being told that photoshop doesnt understand the “open” function. Yet when I look at the dictionary of Photoshop CS it states:

open‚v : open the specified document file(s)
open anything : the file(s) to be opened

All I want to be able to do is to select some files in a folder and have applescript open them up.


tell application "Finder"
	set finderItems to selection
end tell

tell application "Adobe Photoshop CS"
	activate
	repeat with i from 1 to number of items in finderItems
		set this_item to item i of finderItems
		open this_item
	end repeat
end tell

Your script worked fine for me. Are you sure that it’s Photoshop that doesn’t understand the open command? Are you sure that your file selection(s) can be opened by Photoshop?

I modified your script slightly, and this version also worked for me:



tell application "Finder"
	set finderItems to selection
end tell

tell application "Adobe Photoshop CS"
	activate
	repeat with i in finderItems
		open i
	end repeat
end tell






set TheFiles to choose file with prompt "Select image files" of type "TIFF" with multiple selections allowed

This will give you a file menue to choose files from and allow you to get a list of multiple files. It will give you a list of aliases which are more friendly than the finder description returned in your script which probably needs to be coerced into an alias for Photoshop to understand how to use.

The thing is, I will have this application execute after selecting files in a folder. (and there will be many folders). I’ll have this application sitting in my dock for easy access. I don’t wana to have a file menu.

so far… i got this:


tell application "Finder"
	set finderItems to selection
end tell

tell application "Adobe Photoshop CS"
	activate
	repeat with i from 1 to number of items in finderItems
		set this_item to item i of finderItems as string
		open file this_item
	end repeat
end tell

but i want to add a function to make a list of items which match a specific extension:


property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}

tell application "Finder"
	set finderItems to selection
	set finderItemsList to every item of finderItems whose file type is in the type_list or name extension is in the extension_list
end tell


and also run this before opening the file (hehe, i dont want too much do I):


if the name of this_item does not start with "raw_" then
	set name of this_item to "raw_" & the name of this_item
end if

property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}
property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}

set NewList to {}
tell application "Finder"
	set finderItems to selection
	repeat with AnItem in finderItems
		set x to properties of AnItem
		if name extension of AnItem is in extension_list or file type of AnItem is in type_list then copy (AnItem as string) to end of NewList
	end repeat
end tell
return NewList

This should clean up the file list and coerce the list to string from finder item at the same time. You should be able to tack in your rename function fairly easily into this as well.

ok, so now i got this. Its working pretty sweet, just want to rename the file before opening it.

property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct", "psd", "png", "eps"}
property files_list : {}

on run
	tell application "Finder"
		set finderItems to selection
		repeat with this_item in finderItems
			set x to properties of this_item
			if this_item's name extension is in the extension_list then
				if name extension of this_item is in extension_list or file type of this_item is in type_list then copy (this_item as string) to end of files_list
			end if
		end repeat
		if files_list is {} then
			display alert "You havn't selected some image files for editing" buttons {"Ok"} giving up after 10
		else
			my OpenFiles()
		end if
	end tell
end run

on OpenFiles()
	tell application "Adobe Photoshop CS"
		activate
		repeat with this_item in files_list
			open file this_item
		end repeat
		set files_list to {}
	end tell
end OpenFiles

property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}
property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}

set NewList to {}
tell application "Finder"
	set finderItems to selection
	repeat with AnItem in finderItems
		if name extension of AnItem is in extension_list or file type of AnItem is in type_list then
			if the name of AnItem does not start with "raw_" then
				set TheContainer to container of AnItem as string
				set name of AnItem to "raw_" & name of AnItem
				set AnItem to TheContainer & result
			end if
			copy (AnItem as string) to end of NewList
		end if
	end repeat
end tell
return NewList