I have an Applescript that successfully clicks the Replace button in the InDesign Save As dialog, but the same script doesn't work in Photoshop. It fails on the click command in this section of the script:

tell application "System Events" to tell process activeProcess
    click button "Replace" of sheet 1 of front window
end tell

with this message:

Can't get sheet 1 of window 1 of process "Adobe Photoshop CC 2018": invalid index

Here's what the Accessibility Inspector shows for the Replace button: enter image description here I've tried various approaches to identifying the sheet, none of which have worked. Any suggestions?

Just to be thorough, here's what the Save As dialog looks like when the Replace button is available:

enter image description here

Thanks for your help!

  • 1
    You can use Applescript to automate Photoshop (Adobe Photoshop Scripting), which would be a better way to automate things (or using Actions or Javascript). That way you 'd get rid of this issue... — Also if you need to do a lot of GUI button presses or selecting menu items, Keyboard Maestro is amazing for that. Basically, you just tell it what menu items or buttons you wish to press and it does all the heavy lifting. – Joonas Apr 3 '18 at 8:44
  • 1
    Thanks, Joonas. I have looked at Photoshop scripting, but that's more about scripting actions for manipulating the image itself. Clicking the Replace button is a system action, but I need to able to identify it within the Photoshop GUI hierarchy (as worked with the same script in InDesign). I think the problem is mostly about how to refer to the sheet that contains the Replace button. – Sarjo Apr 3 '18 at 16:40
  • First of all... so everyone can see I won't be able to tell you how to click that button with applescript because I simply use Keyboard Maestro when needed and my experience doing that stuff with applescript is very limited. — I don't have the full picture of what you are doing, but you can save documents via scripting, which is what would get rid of the need to click the replace button. If you search the applescript reference pdf for "jpeg save options" or "pdf save options" you'll find code snippets showing how that works. This way you don't need to use applescript to navigate the gui. – Joonas Apr 4 '18 at 7:20
  • Like I said... I don't quite know what it is you're doing besides saving the image, but using applescript to simulate button presses seems a little backwards to me. Also like I mentioned (This may not help with this exact situation) AI and and PS have Actions, that are basically macros. A lot of people start from there and turn to scripting when actions aren't enough. Droplets can also be pretty useful. – Joonas Apr 4 '18 at 7:37

This works for me on the latest version of High Sierra and Adobe Photoshop CC 2018...

delay 1
tell application "System Events"
    click UI element "Replace" of sheet 1 of window ¬
        "Save As" of application process "Adobe Photoshop CC 2018"
    delay 0.3
    click UI element "Large file size (Fastest saving)" of window ¬
        "PNG Format Options" of application process "Adobe Photoshop CC 2018"
    delay 0.3
    click UI element "OK" of window "PNG Format Options" of ¬
        application process "Adobe Photoshop CC 2018"
end tell

enter image description here

  • Thanks, wch1zpink. Unfortunately this doesn't work for me (on High Sierra, Photoshop CC 2018). I get this message: Can't get window "Save As" of process "Adobe Photoshop CC 2018", If I change window "Save As" to front window the window is found but the sheet isn't, and that's the original problem. Identifying the sheet seems to be the issue. – Sarjo Apr 12 '18 at 0:10
  • Updated the code using the latest version of Adobe Photoshop CC 2018 – wch1zpink Apr 14 '18 at 21:38
  • OK, this works if I use it literally -- that is, by identifying "Adobe Photoshop CC 2018" explicity. I was trying to set this up to work in the "Save As" windows of several apps by dynamically identifying the active app, but the script that worked for InDesign wouldn't work for Photoshop. Not sure what the problem was with that, but I'll settle for having a separate script that works just for Photoshop. And thanks very much for your help. – Sarjo Apr 17 '18 at 17:57
  • @Sarjo Glad I can help. You can thank me by voting up my answer and selecting it as the accepted answer. – wch1zpink Apr 18 '18 at 21:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .