PDA

View Full Version : Automator/Apple Script Help - Application Requires Password




nicksoper
Apr 20, 2009, 04:33 AM
Hi There,

Got a very simple question: Can anyone help with some applescript or an automator explanation that will allow an application to open (run) that requires the administrator password to open?

I have a mac mini we are using as an office MAMP server and I would like MAMP running on startup. We currently have the PHP ports set to 80 so that we can access the server through the network by the IP address of the Mac Mini.

Unfortunately running PHP on port 80 means MAMP asks for the password before it will run, which requires a real person to walk over to the machine each time it reboots.

I'm not sure if this should be in mac programming, but I figure it should be a breeze for you veterans.

Just so you know I did try to use automator, I got MAMP opening, but I couldn't fund the option to enter the password when the system asked for it.

Cheers in advance. :D



ergdegdeg
Apr 20, 2009, 04:42 AM
Well, this kind of AppleScript comes to mind:
tell application "System Events"
keystroke "password"
key code 36
end tell
Depends on the workflow of course (if you have to activate the window first, if you have to click in the password text field...)

But: I am by no means a "professional" AppleScript user. Just a bit of self taught knowledge ;)

nicksoper
Apr 20, 2009, 05:08 AM
Hi ergdegdeg,

Thanks so far, and I assure you that your Apple Script is leap years beyond mine! I really appreciate the input.

I've tried what you suggested, but it appears I do need to click the password window (but not the password field).

I've tried nesting your password Apple Script inside the tell application "MAMP" open command, but it doesn't work - I guess the problem is to do with activating the password window first.

If it helps, this mac mini has a fresh leopard install (10.5.6), and its the basic MAMP installation with the PHP port set to 80.

If you could let me know the applescript for this, you'd be a complete legend!

ergdegdeg
Apr 20, 2009, 05:11 AM
What happens if you put in a
tell application "MAMP" to activate
before the one I gave you? I don't know the exact name of the application though, so fill it in ;)

nicksoper
Apr 20, 2009, 05:15 AM
tell application "MAMP"
open
end tell


This opens the application, but gives you the password window - see the attachment.

ergdegdeg
Apr 20, 2009, 05:20 AM
Now it's getting messy :)
simulate CMD + Tab:
tell application "System Events" to key code 48 using {command down}

nicksoper
Apr 20, 2009, 06:01 AM
Sorry to say I'm no closer to getting this as I'm not able to put the fragmented lines together. I've not got the required experience with Apple Script to either nest the commands inside of each other or place then one after each other.

I am guessing the entering of the password command needs to be nested in the initial open application command, as the first command does not complete until MAMP is either open or closed (in which case it throws an error).

I've found a page http://www.onlineaspect.com/2008/12/02/how-to-start-mamp-on-port-80-without-a-password/n which outlines the solution, but he hasn't gone into enough details for me to implement a solution.

Looking forward to some more tips

ergdegdeg
Apr 20, 2009, 07:01 AM
If you want to do it the AppleScript way:
tell application "MAMP" to open
tell application "System Events"
delay 10
key code 48 using {command down}
keystroke "password
key code 36
end tell

what it does:
open MAMP
make a delay of 10 seconds to give MAMP time to start, modify the value if necessary
CMD-Tab to the window
enter the password
press Enter

spydr
Oct 18, 2010, 03:49 PM
awesome tip!

I wanted to open a password protected excel file by automator and this script worked like charm!
:D:D:D