1
votes

Hey guys. Working on Mac OSX 10.6, My "problem" is that I would like a secure password on my user account, but hate the trouble of having to paste it in whenever a process needs admin privileges.

I use Autopilot, and figure it's the best way to input this, so i can 1 use straight applescript to input, 2 use a shell script with "osascript..." 3 launch an applescript compiled application 4 use the text expansion facility in Autopilot (doesn't seem to work in this case)

The script that I have so far is:

    set the clipboard to "FooBar"
    set resultAnything to the clipboard as text

When I execute in script editor my result is "FooBar" But I can't get it to work anywhere else.

I can't use

    set the clipboard to "FooBar"
    tell application "System Events"
    keystroke "v" using command down
    end tell

Because the password dialogue doesn't seem to accept the command+v paste method.

Any help? By the way I did scour the net and stackoverflow before posting this question, so forgive me if I overlooked anything already posted.

Thanks

2

2 Answers

10
votes

Security-wise it's probably better to store your password in the login keychain and retrieve it from there when you need it. (That way you must be logged-in for the password to be available. If you just keep the password in an applescript, it is accessible to anyone who has access to the applescript file.)

Try the following:

  1. Open Keychain Access (/Applications/Utilities)
  2. Press the '+' button at the bottom of the window while the login keychain is selected
  3. Enter a Keychain Item Name, Account Name and your server Password. You will need the Keychain Item Name again.
  4. Make a new Applescript containing the following code, replacing myKeyname with the Keychain Item Name
  5. Select 'Always Allow' and 'Allow' when you first run the script. This will allow Keychain Access to get the password automatically when you are logged in.

The code:

set keyName to "myKeyname" -- replace myKeyname with the Keychain Item Name from step 3
tell application "Keychain Scripting"
    tell keychain "login.keychain"
        set myPass to password of (some key whose name is keyName)
    end tell
end tell
tell application "System Events"
    keystroke myPass
end tell

Credits:

3
votes

tell app "System Events" to keystroke "securepassword" should work, at least if the pasword is alphanumeric. (And you're not invoking the script while holding modifier keys.)