• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Simulating a Modal Dialog
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simulating a Modal Dialog


  • Subject: Simulating a Modal Dialog
  • From: Jonathan Levi <email@hidden>
  • Date: Thu, 10 Sep 2015 21:42:43 -0400

Several months ago, there was brief discussion of creating modal dialogs in AppleScript. Although I agree that true modal dialogs are not possible, the following 2-step procedure illustrates how to make a dialog behave "pseudo-modally";

(* 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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: AS in TextExpander with user interaction
  • Next by Date: Radio button in Acrobat not de-selecting.
  • Previous by thread: Re: AS in TextExpander with user interaction
  • Next by thread: Radio button in Acrobat not de-selecting.
  • Index(es):
    • Date
    • Thread