Reputation: 17
How do I detect if my dialog window has closed?
Then I want to detect if the window dialog closed
on DatabaseRefresher()
menu_click({"OsiriX", "Plugins", "Database", "SetRemoteDatabaseRefresh"})
delay 1
set Test1 to 0
set Test1 to value of static text "RemoteDatabasePrefs" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events"
log Test1
PressButton("Cancel", "OsiriX", "RemoteDatabasePrefs") --(TheButtonToPress, TheProgramName, TheWindow)
Add test here to detect if window closed)
end DatabaseRefresher
Here are my window elements:
button "OK" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events",
button "Cancel" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events",
text field 1 of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events",
static text "RemoteDatabasePrefs" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events"
static text "Enter Remote Database Refresh Interval in minutes:" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events",
button 3 of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events",
button 4 of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events",
button 5 of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events",
As a noob, my apologies if I am asking very basic questions. I do have some existing scripts to work with and I seem to know how they work, but when I try to refactor them I seem to spend too much time find a solution
Upvotes: 0
Views: 992
Reputation: 6092
This line is a bit odd:
set Test1 to value of static text "RemoteDatabasePrefs" of window "RemoteDatabasePrefs" of ...
static text
objects are typically named after the value of the text they contain. Therefore, I would expect the value
of that static text
to be "RemoteDatabasePrefs"
.
But, if this is being done in order to get the header text of a window, you don't need to read the value of some static text
object; you can access the name
property or the title
property for the window
object instead:
set Test1 to the title of window "RemoteDatabasePrefs" of ...
The name
property is clearly set to "RemoteDatabasePrefs"
; title
properties are often identical to the name
, and both usually match the text in the header bar of the window. However, you may have come across an exception, where the name
and title
properties are different in value; in which case, you'll want the value of the title
property, which should match the header text.
To test that the window has been closed, you use the exists
command to test whether or not the window
object still exists. When a window is closed, it ceases to exist from that point onwards.
tell application "System Events to tell process "OsiriX"
set isOpen to (exists window "RemoteDatabasePrefs")
end tell
The variable isOpen
will then contain a boolean value true
or false
telling you whether the window is open (true
) or has been closed (false
).
Upvotes: 1