Applescript: interacting with dialog boxes

Discussion in 'Mac Programming' started by rmurphy07, Apr 9, 2007.

  1. macrumors newbie

    Joined:
    Apr 9, 2007
    #1
    I've written this applescript to mount an AFP volume whenever I am on a certain wireless network. It works just fine, but I am trying to keep from having to hit enter every time it mounts the designated share. My login information is saved in the keychain, I just can't seem to get the Applescript to press "Connect" for me. I know it might sound lazy, but isn't that the point of Applescript? I used UI inspector to figure out the parameters of the "Connect" button.

    Does anyone know how to fix this script so that I do not have to hit enter every time it mounts? Thanks.

     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Check out this article.

    Also check out the mount_afp command.
     
  3. thread starter macrumors newbie

    Joined:
    Apr 9, 2007
    #3
    nope

    I tried the thing mentioned in the macosxhints article, but it still doesn't work. I looked at the mount_afp command, but I don't want to put my username and password in an unencrypted document.

    I have also tried to replace the

    with

    and it still didn't work.

    Thanks for your help, though. I'm still looking for a solution.
     
  4. macrumors G4

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #4
    Did some poking around, and found this, which deals specifically with scripting the Keychain. I'm almost certain that you could use that, combined with the mount_afp command (using the do shell script command in AppleScript to run it), to create a script that retrieves the username and password from the Keychain, then passes those as parameters to the mount_afp command. This avoids storing the username and password insecurely, as you wish.
     
  5. Administrator emeritus

    xUKHCx

    Joined:
    Jan 15, 2006
    Location:
    The Kop
    #5
    I cobbled this together from a script my housemate uses. Don't know where he got it from because i know he can't script.

    It uses the keychain to get the username and password out. Change XX to the number of the item in the keychain. Change YY to the ip of the share you want to mount, can be the bonjour name i.e "richs-imac.local" Set ZZ to the name of the share. Works perfectly on my setup.

    set serverIP to "YY" --enter the ip of the server here
    set ShareName to "ZZ" -- enter the share name here ***Make sure it is in "CAPS"

    try
    tell application "Keychain Scripting"

    set myChain to keychain "login.keychain"
    set username to the account of key XX of myChain
    set pass to the password of key XX of myChain
    end tell
    end try

    tell application "Finder"
    try
    set server_Off to "Server Not On"
    set server_On to "Server Mounted"
    set server_AlreadyOn to "Server Already On"

    (*try
    set ping_result to (do shell script "ping -c 1 -q " & serverIP)

    on error
    display dialog server_Off buttons "OK" default button 1 with icon 1
    error number -128 --user cancelled

    end try -- Commented out because it kept throwing up an error for no reason*)

    mount volume "afp://" & username & ":" & pass & "@" & serverIP & "/" & ShareName
    on error number -55
    display dialog server_AlreadyOn buttons "OK" default button 1 with icon 1
    error number -128 --user cancelled
    end try
    end tell
     
  6. thread starter macrumors newbie

    Joined:
    Apr 9, 2007
    #6
    got it!

    Hi friends,
    Someone suggested using Keychain scripting to get this to work without me having to put my username and password into an unencrypted document. Here is the final script. It works beautifully. Thanks for all of your help. I wanted to post the script for everyone's benefit and elation.

     
  7. Administrator emeritus

    xUKHCx

    Joined:
    Jan 15, 2006
    Location:
    The Kop
    #7
    Just being paranoid but i would strip your post with "sensitive" data such as the the various names of things. Just a thought.
     
  8. thread starter macrumors newbie

    Joined:
    Apr 9, 2007
    #8
    Thanks for your concern. I am not worried about those particular details.
     

Share This Page