Applescript click window button help!

Discussion in 'Mac Programming' started by ElectricMan5, Mar 16, 2009.

  1. ElectricMan5
    Expand Collapse
    macrumors regular

    Joined:
    Jul 22, 2008
    #1
    I'm using this script:

    tell application "System Preferences" to activate

    tell application "System Events"
    tell process "System Preferences"
    click button "Network" of window "System Preferences"
    delay 1
    end tell
    end tell


    It compiles well, but it doesn't run!

    It comes up with the error:

    System Events got an error: Can’t get button "Network" of window "System Preferences" of process "System Preferences".


    I want the script to automate opening up system preferences, then opening up sharing, then turning "web sharing" on and off.

    Please help! Thanks.
     
  2. kainjow
    Expand Collapse
    Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    This would be a better way to show the Sharing preference:
    Code:
    tell application "System Preferences"
        set current pane to pane id "com.apple.preferences.sharing"
    end tell
    Then after that you can use UI scripting.
     
  3. ElectricMan5
    Expand Collapse
    thread starter macrumors regular

    Joined:
    Jul 22, 2008
    #3
    Thanks! What is UI Scripting, though?
     
  4. kainjow
    Expand Collapse
    Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    It's accessing the controls (buttons, text fields, etc) of a program via AppleScript, which is what the "click" command is. You would only use it when there isn't a built-in way of doing what you want through AppleScript. Perfect example is above where System Preferences already supports showing a certain preference pane, but you were wanting to manually click the button instead.
     

Share This Page