Image Events opens Photoshop

Hi all,

First post here. I have a very simple applescript that is supposed to get the dimensions of an image and then go on from there to do run actions in photoshop based on the dimensions. However, it insists on opening photoshop on the Image Event command ‘open’. I’m totally new to applescript, so I’m sure I’m doing something wrong here. I just don’t know what.

Here it is and thanks in advance for any help:

tell application “Finder”

activate

set sourceFile to choose folder with prompt "choose folder"

set these_items to get every item of (entire contents of folder sourceFile) whose kind ≠ "Folder"

-------

repeat with i from 1 to the count of these_items
	
	set this_item to (item i of these_items)
	
	--------
	
	tell application "Image Events" <-----------------------------------(this part doesn't work)
		
		launch
		
		set theImage to open this_item
		
		set {x, y} to this_item's dimensions
		
		if x > y then
			
			delay 15
			
			--------
			
			tell application "Finder" to tell (open (this_item))
				
			end tell
			
			tell application "Adobe Photoshop CC 2015"
				
				activate
				
				delay 0.25
				
				do action "MB-DrivePhotos-Horiz" from "Skelly_Actions"
				
			end tell
			
			---------
			
		else if x < y then
			
			tell application "Finder" to tell (open (this_item))
				
			end tell
			
			tell application "Adobe Photoshop CC 2015"
				
				activate
				
				delay 0.25
				
				do action "MB-DrivePhotos-Horiz TEST" from "Skelly_Actions"
				
			end tell
			
		end if
		
	end tell
	
end repeat

end tell

Model: iMac
AppleScript: AppleScript 2.4
Browser: Safari 537.36
Operating System: Mac OS X (10.10)

Hi,

your script is quite confusing and there are many issues.

Actually you don’t need Image Events at all. Let Photoshop do everything (aside from the Finder part).
The activate lines are not needed either.

If you want to close and save the current document remove the comment dashes

set sourceFolder to choose folder with prompt "choose folder"
tell application "Finder"
	set these_items to get every file of (entire contents of sourceFolder) as alias list
end tell
repeat with aFile in these_items
	tell application "Adobe Photoshop CC 2015"
		open aFile
		tell document 1 to set {theWidth, theHeight} to {width, height}
		if theWidth > theHeight then
			do action "MB-DrivePhotos-Horiz" from "Skelly_Actions"
		else
			do action "MB-DrivePhotos-Horiz TEST" from "Skelly_Actions"
		end if
		-- close document 1 saving yes
	end tell
end repeat

Wow.

Thanks, Stefan.

Yes, I’m learning as I’m doing and I see now that I was making the script do a lot it didn’t need to. I’ll look further into what can be done directly in Photoshop via applescript commands.

Thanks again,
Mark

:slight_smile: