help with button warning/dialog display scripting

Is there anybody out there skilled enough in the art of scripting who knows how to fix my problem?
heres what i'm trying to do is:
On startup: open system preferences > open the 'sharing' pane > open internet tab > press stop > press start > press start> close > end

my problem being the second start. the second start appears in the form of a drop down dialog display, asking/warning me do I really want to turn on internet sharing. I have looked around and tried many ideas but none seem to work.

so far me script looks like:

"
tell application "System Preferences"
activate
end tell

tell application "System Events"
tell process "System Preferences"
click menu item "Sharing" of menu "View" of menu bar 1
delay 10
tell window "Sharing"
if (exists tab group 1) then
tell tab group 1
click radio button "Internet"
delay 1
click button "stop"
delay 1
click button "Start"
delay 1
click button "start"
delay 1
end tell
end if
end tell
end tell
end tell

ignoring application responses
tell application "System Preferences" to quit
end ignoring
"

can some one please help me?

iMac, Mac OS X (10.4.11)

Posted on Oct 30, 2010 6:24 AM

Reply
7 replies

Oct 30, 2010 12:22 PM in response to urahara kisuke

Why do you need to do this every time you start the machine? There might be a simpler way.

-------------

You could try "pressing" the return key after the message.

delay 3
keystroke return

An example. Be sure to follow advice in first comment:

(*
Remember you need to enable assistive devices.
This lets applications software access screen elements.

blue apple > system perferences > universal access > enable assistive devices
*)

-- Write a message into the event log.
(*
Run this program from the Script Editor. Click on the Event Log tab at the
bottom of the screen.
*)
log " --- Starting on " & ((current date) as string) & " --- "


set the_item_ref to choose file with prompt "Select an html, text, or some other file Safari will display."

-- Activate
activate application "Safari"

-- Open the URL
tell application "Safari"
open the_item_ref

-- print
-- System Events interacts with the current active applications.
tell application "System Events"
tell process "Safari"
-- Your simulating typing on the keyboard. You need to allow time
-- for the application to run. It's always a guess about delay in seconds.
delay 3

-- Be sure your printer is up & running before printing.
keystroke "p" using command down
delay 3
keystroke return
delay 10
keystroke "w" using command down

end tell
end tell

end tell -- of Safari




Robert

Nov 5, 2010 11:21 AM in response to BDAqua

I found the panel. Doesn't seem to accept shortcuts.

You could try some mouse clicking tool.

Here is one:
-- Go after time message
(move mouse {543, 276})
click mouse

-- get rid of SpeakPad could not start message
(*
delay 3
tell application ""
activate
end tell
move mouse {512, 255} -- center mouse
delay 2
click mouse
*)
-- center mouse
do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep 'Resolution'" -- get info
tell the result to set {DisplayWidth, DisplayHeight} to {word 2, word 4} -- get resolution
move mouse {DisplayWidth div 2, DisplayHeight div 2} -- center mouse

(*
First, there is the XTools scripting addition, which will give AppleScript the ability to move the mouse.

http://www.lestang.org/osax/XTool/
XTool-2.0-src.dmg.tgz

Installation :

Drag XTool.osax from insite the image to one of the following locations (create the directory if it does not exist) :

a : ~/Library/ScriptingAdditions/
b : /Library/ScriptingAdditions/
c : /System/Library/ScriptingAdditions/

I have it in directory /System/Library/ScriptingAdditions/
My other two directories do not exit: ~/Library/ScriptingAdditions/ &
/Library/ScriptingAdditions/

. Next, you will need to place a script application into your login items (System Preferences > Accounts > Login Items) that will move the mouse when you log in:

*)


------------

System events has a click command. You could use it. This avoids the problem of using absolute screen coordinates.

---------

You can adjust the position of the click based on the address of the perefence pane. It's in this code:

(*
Required:

xcode
http://discussions.apple.com/message.jspa?messageID=10613253#10613253

Macintosh-HD -> Applications -> Utilities -> Terminal

Click
http://www.macosxhints.com/article.php?story=2008051406323031

clickdrag
http://www.macosxhints.com/article.php?story=2008051406323031

Microsoft Word

Play Sound
http://microcosmsoftware.com/playsound

Turn on accessability GUI in system preferences.

Optional:
--------
Full Key Codes
http://www.versiontracker.com/dyn/moreinfo/macosx/21215

findCursorLoc
findCursorLoc, applescript code, is listed below. Assign this code to a function key.
move cursor to desired location, press function key:
requires:
XTools scripting addition gives AppleScript the ability to move the mouse.
http://www.lestang.org/osax/XTool/
XTool-2.0-src.dmg.tgz
-- begin findCursorLoc --
do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep 'Resolution'" -- get info
tell the result to set {DisplayWidth, DisplayHeight} to {word 2, word 4} -- get resolution

set {xWidth, yHeight} to position of the mouse
display dialog "DisplayWidth= " & DisplayWidth & " DisplayHeight=" & DisplayHeight & return & " xWidth=" & xWidth & " yHeight=" & yHeight
-- end findCursorLoc --

youpi or iKey
youpi and iKey are keystroke remapping programs.
youpi, the free version, works fairly well for me in Mac OS 10.4 although not officially supported.
http://www.versiontracker.com/dyn/moreinfo/macosx/11485&vid=75326
iKey is the paid version
http://www.scriptsoftware.com/ikey/

*)
-- Script results from blizzard of '10 & no DSL connection. Hence, I've time to program.

on run
-- Write a message into the event log.
-- To see, run this applescript in Sript Editor. Click on Event Log tab at bottom of screen.
-- Click run.
log " --- Starting on " & ((current date) as string) & " --- "

set theApp to "Microsoft Word"

-- the folder containing click & clickdrag binary
set theClickLoc to "/Users/mac/clickcode/"

-- Should not need to be changed.
set theSoundLoc to ((path to system folder) as string) & "Library:Sounds:"

--- We have arrived.
(*
Play Sound
http://microcosmsoftware.com/playsound/
*)
tell application "Play Sound"
play theSoundLoc & "Funk.aiff" repeat 4
end tell

-- For debugging,make sure your application is closed.
-- Start your application
tell application theApp
activate
end tell

delay 10

tell application "System Events"
tell process theApp

tell application "Play Sound"
play theSoundLoc & "Funk.aiff" repeat 2
end tell

-- get rid of initial idiot panel
key code 53 -- escape key
delay 2

end tell
end tell
-- end For debugging

-- normal start point.
tell application "System Events"
tell process theApp

tell application "Play Sound"
play theSoundLoc & "Hero.aiff" repeat 3
end tell

-- open file menu
keystroke "o" using command down

end tell
end tell

say "Display open file panel, soon. if not already."

-- debug stuff
try
tell application "System Events"
set processList to get every UI element of process theApp

log "processList=..."
log processList

set processList to get name of every UI element of process theApp

log "processList=..."
log processList
set processList to get position of every UI element of process theApp

log "processList=..."
log processList
end tell
on error
log "no " & theApp & " today"
end try
-- end debug stuff

-- loop error escape value
set opsCount to 0

-- Wait until the file open window appears

set processList to {} -- repeat until requires processList to be defined.
(* repeat until may need adjustment *)
repeat until (processList contains {"Open: " & theApp})

-- prevent an endless loop
set opsCount to opsCount + 1
if opsCount > 120 then
display dialog "Logic error " & theApp & " never opened a open file window." giving up after 120
return
end if

delay 0.2

try
tell application "System Events"
set processList to get name of every UI element of process theApp
log "processList=..."
log processList
end tell
on error
log "no " & theApp & " today"
end try

end repeat

say "We are about to start dragging."

-- Allow for moving open file panel
-- Start by getting current position
try
tell application "System Events"
-- alternative, should only be one position:
-- set prositionList to get position of every UI element of process theApp whose name starts with "Open:"

set prositionList to get position of front window of process theApp
log "prositionList=..."
log prositionList
end tell
on error
log "no " & theApp & " today, point 3"
display dialog "Logic error " & theApp & " no position for open file window." giving up after 120
return
end try

-- Make adjustment for moving open file panel
set prositionX to item 1 of prositionList
set prositionY to item 2 of prositionList
log "prositionX= " & prositionX & " prositionY = " & prositionY

set actualX to prositionX + 154
set actualY to prositionY + 233

-- Widen folder & disk list in open panel.
-- move to start of drag.
try
-- for debug drag point is currently -x 198 -y 288
set see to theClickLoc & "click -x " & actualX & " -y " & actualY
log "see= " & see
set results to do shell script see
on error theError
display dialog "click error found. results for " & theError
end try

-- Drag
try
-- -x 266 -y 288
-- drag is 68 pixels to the right
set see to theClickLoc & "clickdrag -x " & actualX + 68 & " -y " & actualY
log "see= " & see
set results to do shell script see
on error theError
display dialog "clickdrag error results for " & theError
end try

say "good news, Drag complete."

end run

Nov 6, 2010 1:15 PM in response to urahara kisuke

urahara kisuke wrote:
the second start appears in the form of a drop down dialog display...


This GUI element is known as a "sheet." You might try adding some variation of the following after your final *click button "Start"* command:

*tell application "System Events"*
*tell process "System Preferences"*
*click button "OK" of sheet 1 of window "Sharing"*
*end tell*
*end tell*

Note that due to security concerns, I haven't fully tested this; but I had no trouble getting *click button "Cancel" of sheet 1 of window "Sharing"* to work in a similar test.

Good luck. Hope this helps.

Nov 11, 2010 2:33 AM in response to Andrew99

THANK YOU VERY MUCH!!!


"
tell application "System Preferences"
activate
end tell

tell application "System Events"
tell process "System Preferences"
click menu item "Sharing" of menu "View" of menu bar 1
delay 4
tell window "Sharing"
if (exists tab group 1) then
tell tab group 1
click radio button "Internet"
delay 1
click button "stop"
delay 1
click button "Start"
delay 1
end tell
end if
end tell
end tell
end tell

tell application "System Events"
tell process "System Preferences"
click button "Start" of sheet 1 of window "Sharing"
end tell
end tell
"

Worked ^_^
adding "click button "Start" of sheet 1 of window "Sharing"" later on worked!

Message was edited by: urahara kisuke

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

help with button warning/dialog display scripting

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.