Applescript to answer dialog

Hi,
I am just learning applescript.. sorry in advance if I don't explain clearly.

I am writing a script that tells Adobe Illustrator to run an action but I need to add to the script that if a dialog appears, answer it with a return. Is it possible to have the script answer a dialog while running the action? If so, any help on the scripting would be greatly appreciated!
Note: I can not prevent the dialog from coming up at all.. I need it to answer the dialog with a return.
(I needed to add a menu item to the actions that requires a dialog to come up)

If you need to know more details, let me know.
Thanks so much!!
Winnie

iMac, Mac OS X (10.6.3)

Posted on Sep 22, 2010 10:21 AM

Reply
3 replies

Sep 22, 2010 10:45 AM in response to Winnie Brown

Here is an example:

Notice
You need a delay to wait for the dialog to appear
delay 1

simulate the return key
keystroke return

don't forget

tell application "System Events"

on open dropped_items
-- Remember you need to turn on enable assistive devices
-- this lets applications software to access screen elements
-- blue apple > system perferences > universal access > enable assistive devices

-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "
-- set see to alias "Macintosh-HD:Users:mac:Desktop:app.html"
-- set dropped_items to {see}

set the_app to "Safari"


repeat with dropped_item_ref in dropped_items
--set UrlBase to "xzzx FILE://" & POSIX path of dropped_item_ref
--display dialog UrlBase

-- Activate
activate application the_app

-- Open the URL
tell application the_app
open dropped_item_ref
-- print dropped_item_ref
tell application "System Events"
tell process the_app
delay 3
-- click menu item "Print..." of menu "File" of menu bar 1
keystroke "p" using command down
delay 1
keystroke return
delay 10
keystroke "w" using command down

end tell
end tell

--quit
end tell

end repeat
end open

Sep 22, 2010 10:45 AM in response to Winnie Brown

There isn't a way for an AppleScript to know when an application puts up a dialog. However, if you know when the dialog is going to be put up, you can just add a statement in your *Adobe Illustrator* tell statement (when the application is activated) to keystroke a return:

tell application "System Events" to keystroke return

This assumes that the default for the dialog is what you want and that GUI scripting is enabled by having the *System Preferences > Universal Access > Enable access for assistive devices* checkbox is checked.

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.

Applescript to answer dialog

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