March 8, 201015 yr Hi, I have a multi Window Solution and qould like to ask if its possible to check if a Window is open or not. Because I would like to avoid the same window more than once at a time. thx ChiSao
March 8, 201015 yr Function "WindowsName" returns a list with the name of all windows. Do a patterncount with the window you want to check to see if it exists. Eg WindowNames return Window_a Window_a0 Window_B If you check for "Window_a" it will return 2. For better result check for a custom function in fmfunctions.com or briandunning.com that will allow to check the exact presence of an element name in the list.
March 8, 201015 yr Commit records If[ValueCount(windowNames(Get(WindowName)))>1] Close window [current window] End if
March 8, 201015 yr No need for a custom function. Let([ //Grab window names windows = WindowNames(Get(FileName)); //add pilcrow as delimiter windows = ¶ & windows & ¶; //Grab test window name thisWindow = Get(WindowName); //add delimiter thisWindow = ¶ & thisWindow & ¶; //test test = PatternCount(windows;thisWindow) ]; test )
March 9, 201015 yr I should have commented that the testWindow = Get(windowName) should really be testWindow = "The Name of Window". As written, the result will always be true.
March 10, 201015 yr In fact, the calculation you wrote is what my CF would look alike. It is always useful to have a custom function that checks if an element is in a list. It's even easier with FM11 since we can now import CF :.
August 14, 201015 yr Newbies Found a very quick and easy way to test whether a window exists: If [ Position ( WindowNames; "{window name}¶" ; 1 ; 1 ) > 0 ] Replace {window name} with the name of the window you are looking for. Since the WindowNames function returns a list of names followed by carriage returns, the ¶ symbol is necessary to distinguish between similarly named windoes. For example, if you performed a "new window" command while the window you are looking for (say "Contacts") is open, FM will create a new window with the same name followed by " - 2" or " - 3" etc (e.g. Contacts -2, Contacts -3). With the ¶ FM will always refer to only the original window.
August 14, 201015 yr If [ Position ( WindowNames; "{window name}¶" ; 1 ; 1 ) > 0 ] This will fail in two cases: (a) when the window you are looking for is the last one on the list (no trailing ¶), and (: when an existing window has a name that ends with with searched name. It's best to use the FilterValues() function for this.
August 16, 201015 yr Newbies Right you are! In my case the window I am looking for is named "Contacts," so I entered the following and it works better than my prior post: If [FilterValues ( WindowNames ; "Contacts" ) ≠ ""] I love one-line solutions. Thanks!
August 16, 201015 yr Don't use ≠ "" this never has been a good practice and I believe that it now breaks in some circumstances. Use instead the IsEmpty() function - that's what it's for. Or in this eaxmple, Not Isempty. Not Isempty( FilterValues ( WindowNames ; "Contacts" ) )
March 14, 201114 yr This is brilliant works great for me, however I would like to make it so that if the window starts with a name in this case Event Detail it will work. eg Not Isempty( FilterValues ( WindowNames ; "Event Deail" ) ) Thought about using a left function but can not get my head around where to implement it. Can anyone help. John
March 14, 201114 yr There is an alternative method to determine whether a window is open: select the window by name and see whether there was an error. Set Error Capture [on] Select Window [ windowname ] Set variable [ $error ; Get( lastError ) ] Set Error Capture [off] If [ $error = 0 ] #window with that name exists and is selected End If
March 14, 201114 yr Hi Vaughan, Thank you for the code, looks great and I think it would work well for me. However I am still not sure how to get it to return when I only want it to check the start of the Window name. For example, the window´s name is "Event Detail - and the date of the event" So I want it to select any window that starts Event Detail regardless of the other information that follows it. Sorry if i am missing something obvious. many thanks John
July 21, 201312 yr Try: If [ Position ( ¶ & WindowNames ; ¶ & "Event Detail" ; 1 ; 1 ) ] ... Sorry for being dense, but where would that line of code go in the script? Also, say I have more than one window open beginning with the name, WEBSITE; how would I close all those windows in one shot?
July 22, 201312 yr Your script would look something like this, considering that you use a global text field called Phrase to hold the portion of the window name you are looking for: Script Name: Close all phrase windows Set Variable [ $windows ; Value: WindowNames ] Loop Exit Loop If [ Let ( $count = $count + 1 ; $count > ValueCount ( $windows ) ) // we're counting through all the windows ] If [ LeftWords ( GetValue ( $windows ; $count ) ; 1 ) = tableName::Phrase // or replace blu field reference to Phrase with text as "website" ] Close Window [ Name: GetValue ( $windows ; $count ) ; Current file ] End If # End Loop ADDED: I thought it faster and best to set a variable with the window names instead of recalculating WindowNames again each time but ... if Users continually are opening a WEBSITE window then some might be opened while the script is running (although unlikely). However small, the possibility exists so you may wish to loop the WindowNames instead.
Create an account or sign in to comment