4

I'm new to applescript and is currently stuck in access the prompt window asking for my password.

I'm creating a launcher for my daily use application and i want to automate the launching process.

Right now, I'm only launching two application, VirtualHostX and MAMP. Later I might add few some.

Here's what I done so far:

tell application "VirtualHostX" to activate
tell application "MAMP" to activate

tell application "System Events"
    tell process "VirtualHostX"
        tell menu bar 1
            tell menu bar item "Web Server"
                tell menu 1
                    click menu item "Start"
                end tell
            end tell
        end tell
    end tell
end tell

When launching, It will launch the two application successfully, but Virtual Host will ask me for my password for authorization. I want to integrate entering my password in the flow or code. I already tried to google for answer but failed to find a solution for it.

I can't seem to target that window and enter my password. enter image description here

Let me know what am I missing.

Thank You.

2 Answers 2

6

Password dialogs are shown by SecurityAgent:

tell application "System Events" to tell process "SecurityAgent"
    set value of text field 2 of scroll area 1 of group 1 of window 1 to "password"
    click button 2 of group 2 of window 1
end tell
2
  • Works like a charm, Lauri.
    – Pennf0lio
    May 30, 2013 at 12:12
  • I think something happened with Yosemite that makes this not work anymore. Any suggestions?
    – nvrtd frst
    May 15, 2015 at 1:31
1

For Yosemite, the SecurityAgent dialog box is different. This will work:

tell application "System Events"
    tell process "SecurityAgent"
        set value of text field 2 of window 1 to "yourPassword"
        click button 2 of window 1
    end tell
end tell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.