(* Following script, "SimulateNonmodalFinderDialog-Driver.scpt", calls a script application, "SimulateNonmodalFinderDialog.app", to display a dialog; then this script manipulates the dialog window. Information is returned from the dialog via the Clipboard.
*)
ignoring application responses
do shell script "open $HOME/Development/SimulateNonmodalFinderDialog/SimulateNonmodalFinderDialog.app"
delay 0.5
end ignoring
toggleFinderDialogPosition()
activate
paragraphs of (the clipboard)
on toggleFinderDialogPosition()
set {pos1, pos2} to {{930, 20}, {940, 20}}
tell application "System Events" to tell process "Finder" to repeat while (exists window "")
set absValX to my absVal((item 1 of ((position of window "") as list)) - (item 1 of pos1))
set absValY to my absVal((item 2 of ((position of window "") as list)) - (item 2 of pos1))
if (absValX < 5 and absValY < 5) then
set position of window "" to pos2
else
set position of window "" to pos1
end if
delay 0.5
end repeat
end toggleFinderDialogPosition
on absVal(num)
if num ≥ 0 then
return num
else
return -num
end if
end absVal
(* SimulateNonmodalFinderDialog.app
Return results to clipboard, even if calling process ignores responses.
*)
tell application "System Events" to set savedProc to item 1 of (processes whose frontmost is true)
showFinderDialog()
on showFinderDialog()
tell application "Finder"
activate
with timeout of 3600 seconds
try
set dialogAnswer to (display dialog "Change the answer if you wish, then dismiss this dialog." default answer "Default answer")
set the clipboard to (button returned of dialogAnswer & return & text returned of dialogAnswer)
on error
set the clipboard to ("Cancel" & return & "")
end try
end timeout
end tell --Finder
end showFinderDialog
tell application "System Events" to set savedProc's frontmost to true
paragraphs of (the clipboard) --only if you want to run this alone