Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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.

Commit records

If[ValueCount(windowNames(Get(WindowName)))>1]

Close window [current window]

End if

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

)

  • Author

Thx a lot!

Exactly what I was looking for

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.

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 :.

  • 5 months later...
  • 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.

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.

  • 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!

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" ) )

  • 6 months later...

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

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

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

Try:

If [ Position ( ¶ & WindowNames ; ¶ & "Event Detail" ; 1 ; 1 ) ]

...

Brilliant Comment, just worked out how this works, Just what I need. Thank you

  • 2 years later...

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?

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.