hi
i’m brand new to applescript and very quickly ran into the problem of applescript not being able to wait on a button being pushed… after a few days of experimenting, i came up with the attached solution…
(the app i need this for isn’t textedit but i used textEdit for this example since i assume everyone has it and it uses the same print dialog… basically, for this portion of the script, i need to get the user’s desired paper size for printing which will then be used to set the window size to the same aspect ratio)
[EDIT] i guess i should state the goal …i want the ‘page setup…’ dialog to come up then the user can select and/or change their paper size and orientation… when they press ‘ok’ (or cancel) within the actual dialog, the dimensions of their paper has been assigned to a variable for use further along in the script…
[EDIT2] …for this bit to work, you’ll have to have text edit and a window open…
tell application "TextEdit"
activate
tell application "System Events" to tell process "TextEdit"
set AppleScript's text item delimiters to {" "}
click menu item "Page Setup." of menu 1 of menu bar item "File" of menu bar 1
repeat until focused of text area 1 of scroll area 1 of window 1 = true
try
set psz to value of static text 2 of sheet 1 of window 1
if value of radio button 1 of radio group 1 of sheet 1 of window 1 = 1 then
set PaperWidth to first text item of psz
set PaperHeight to third text item of psz
else
set PaperWidth to third text item of psz
set PaperHeight to first text item of psz
end if
end try
end repeat
display dialog "width = " & PaperWidth & "
height = " & PaperHeight
end tell
end tell
i guess my question is: Is there anything inherently wrong with this approach? in the end, it does do what i want it to do but i’m concerned with the fact that the variables are being updated so often while in the repeat cycle… is this burning through system resources or taxing the system in a way i need to be concerned with?
or, is there a better approach to making something like this happen using applescript?
thanks
jeff
Model: quad2.66macPro/ 15"i7mbp
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)