skip to Main Content

How to write the code correctly?

I run the application Photoshop in the automator
I’m waiting for it to fully load
Then I press 10 times Tab and press Enter.

I’ve tried that:

enter image description here

Looks like that part doesn’t work. Because Tab starts to click before the application is fully loaded. What’s wrong? Thanks!

repeat until application launch
delay 0.5 end repeat delay 0.5

3

Answers


  1. Chosen as BEST ANSWER

    This is the answer:

    tell application "Your app"
        launch
        activate
    end tell
    

  2. I don’t know much about Photoshop, but I know that it has a loading screen. I tried the following code in Affinity Photo which is a similar product to Photoshop.

    tell application "Photoshop"
        launch
        set theBool to false
        repeat until theBool
            tell application "System Events" to ¬
                if menu item "Close" of ¬
                    menu 1 of ¬
                    menu bar item "File" of ¬
                    menu bar 1 of ¬
                    application process "Photoshop" exists then ¬
                    set theBool to true
            delay 0.2
        end repeat
    end tell
    

    The repeat until theBool checks if the loading screen is over by checking if some menu item exists which isn’t available when the loading screen is open. If the "Close" and the "File" don’t work in Photoshop, you may choose something else.

    Login or Signup to reply.
  3. Most likely, the OP does not understand the main thing: GUI scripting (in this case, sending 10 tabs, and then Enter, that is, keystroke tab and keystroke return in AppleScript language) only works with the frontmost window. And the launch command launches an application without bringing its window to the front.

    The correct approach is 1) use the activate application "Photoshop" command 2) use the make new document command, 3) check if the new window exists, 4) send keystroke commands. In the Automator, the Run AppleScript action should be something like this:

    on run {input, parameters}
        tell application "Photoshop"
            activate
            make new document with properties {name:"myNewDocument"}
            repeat until window "myNewDocument" exists
                delay 0.1
            end repeat
        end tell
        tell application "System Events"
            repeat 10 times
                delay 0.1
                keystroke tab
            end repeat
            keystroke return
        end tell
        return input
    end run
    

    NOTE: not tested, because PhotoShop.app is not installed on my Mac. I am ready to correct my script, if needed. In general, the question is not quite clear.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search