System Events and Photoshop 2024

Prior to upgrading to Photoshop 2024, the code below would work just fine. It appears that I now have to target Photoshop via System Events by using “Adobe Photoshop 2024”. Is there anyway to use a generic version of Photoshop in the code in case the version of Photosop should ever change?

tell application "System Events"
	tell application process "Photoshop CC"
		set frontmost to true
end tell
end tell

Can you just use this instead:

tell application id "com.adobe.Photoshop" to activate

Or do you specifically need frontmost?

Pretty sure that’s what Jeffkr needs Leo_r. No System Events involved.

tell application id "com.adobe.Photoshop"
	tell document 1
		art layers -->art layer 1 of document "Untitled-1"
	end tell
end tell

I was using system events to trigger keyboard shortcuts, so frontmost in this case was not exactly the issue. I am actuall looking for a way to trigger a keyboard shortcut that is not accessible via a menu item selection.

tell application id "com.adobe.Photoshop"
	activate
	tell application "System Events"
		keystroke "b" using command down
	end tell
end tell
1 Like

I would use Paul’s suggestion. If for some reason you want to specify the process name, you might consider the following, which worked with Safari:

tell application id "com.apple.Safari" to activate
delay 0.3 --may not be needed
tell application "System Events"
	set theProcess to name of first process whose frontmost is true
	tell process theProcess
		keystroke "n" using command down
	end tell
end tell

I apologize for the oversight in my initial post. I didn’t realize that the need involved the execution of menu selections, specifically the “Paste Into” command, which I couldn’t find in the Photoshop scripting dictionary.

I understand that “Select All” does not require System Events in the snippet below. However, Peavine’s suggestion works perfectly. I’ve included the entire code snippet in case someone knows of another method to “Paste Into” an active selection in Photoshop, without selecting a menu bar item.

Thank you all once again for your help.
-Jeff

tell application id "com.adobe.Photoshop"
	activate
	tell application "System Events"
		set theProcess to name of first process whose frontmost is true
		tell process theProcess
			delay 0.1
			keystroke "a" using {command down} -- select all
			delay 0.1
			tell menu bar 1
				tell menu bar item "Edit"
					tell menu 1
						tell menu item "Paste Special"
							tell menu 1
								click menu item "Paste Into"
							end tell
						end tell
					end tell
				end tell
			end tell
			delay 2
			key code 76 --enter
		end tell
	end tell
end tell

I found that this works as well, setting the application id to variable that System events can later access.

set myPhotoShop to application id "com.adobe.Photoshop" as string
tell application "System Events"
	tell application process myPhotoShop
		--do menu items
	end tell
end tell
tell application id "com.adobe.Photoshop"
	tell document 1
		activate
		paste with clipping to selection
	end tell
end tell
1 Like

Wow! This is excellent! I greatly appreciate you sharing this paulskinner!