Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 16, 2009, 12:28 PM   #1
ElectricMan5
macrumors regular
 
Join Date: Jul 2008
Applescript click window button help!

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.
__________________
21.5" 2012 iMac, 3.1 Ghz i7, 16GB RAM, 1TB HD; 13" Aluminum Unibody Macbook, 2 Ghz, 2 GB RAM, 160 GB HD ; 64 GB iPod Touch 4g; 8GB iPhone 3g; 32GB iPhone 4s
ElectricMan5 is offline   0 Reply With Quote
Old Mar 16, 2009, 01:56 PM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote
Old Mar 16, 2009, 02:00 PM   #3
ElectricMan5
Thread Starter
macrumors regular
 
Join Date: Jul 2008
Quote:
Originally Posted by kainjow View Post
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.
Thanks! What is UI Scripting, though?
__________________
21.5" 2012 iMac, 3.1 Ghz i7, 16GB RAM, 1TB HD; 13" Aluminum Unibody Macbook, 2 Ghz, 2 GB RAM, 160 GB HD ; 64 GB iPod Touch 4g; 8GB iPhone 3g; 32GB iPhone 4s
ElectricMan5 is offline   0 Reply With Quote
Old Mar 16, 2009, 02:21 PM   #4
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Using Javascript | Applescript to click button in Safari o.rka Web Design and Development 4 Feb 18, 2014 05:15 PM
entire window moves when attempting to click and drag element in window HELP chlc MacBook Pro 0 Feb 10, 2014 05:08 PM
Applescript Safari how to click button redwgaontoy Mac Programming 1 Jun 12, 2013 12:12 AM
Keep a window always on top - can't find an app. How can I applescript this? Hippocrates04 Mac Basics and Help 0 Aug 5, 2012 10:36 AM
AppleScript To Click One Button Only If Another Button Is Unavailable JonHimself Mac Programming 2 Jul 4, 2012 01:16 PM

Forum Jump

All times are GMT -5. The time now is 06:22 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC