MBS FileMaker Advent calendar - Door 17 - User Notifications
![]() |
![]() |
![]() |
Day 17 - User Notifications |
Advent is running faster and faster and there are not many days left until Christmas. We want our monkey to keep an eye on the time and so we always want to receive a user notification when FileMaker is opened showing how many days are left until Christmas.
I will now show you how this works with our user notifications under Windows and Mac.
First we have to determine the number of days left until Christmas. We always start from the current year, so if it is December 30th we want a negative number to come out. First we get the current date in a variable. Then we determine the date of December 25th in the current year by taking the year from the current date. Internally, a date value is seen as a number of days since a specified day. For this reason, we get the exact number of days by subtracting the current date from the Christmas date.
Set Variable [ $CurrentDate ; Value: GetAsNumber ( Get(CurrentDate) ) ] Set Variable [ $CurrentYear ; Value: Year ( Get(CurrentDate) ) ] Set Variable [ $ChrismasDate ; Value: GetAsNumber ( Date ( 12 ; 25 ; $CurrentYear ) ) ] Set Variable [ $DaysUntilChristmas ; Value: $ChrismasDate-$CurrentDate ]
We would like to return individualized results depending on the value. If Christmas is still to come this year, i.e. the number is greater than 0, then we write as the title how many days there are left until Christmas and in the text that the monkey should hurry because there is still a lot to do. On Christmas Day (value 0) we wish him a Merry Christmas. If this is not the case, then the value is less than 0 and we are between Christmas and New Year's Eve and our monkey has missed Christmas.
If [ $DaysUntilChristmas > 0 ] Set Variable [ $Title ; Value: $DaysUntilChristmas & " days until Christmas" ] Set Variable [ $Text ; Value: "Hurry up! There's still a lot to do!" ] Else If [ $DaysUntilChristmas = 0 ] Set Variable [ $Title ; Value: "HoHo Merry Christmas" ] Set Variable [ $Text ; Value: "It's Christmas! Grab your presents and keep up the good work! " ] Else Set Variable [ $Title ; Value: "You missed Christmas! Maybe next year." ] Set Variable [ $Text ; Value: "You can take it easy now. " & "There's still plenty of time until next Christmas. " & "Give yourself a break" ] End If
After we have determined the days and the corresponding titles and texts, we now want to create the notifications. Here we have to make a distinction depending on the operating system, because we have different function areas in the plugin for Mac/iOS and Windows. For Mac and iOS we use the functions from the UNNotification topic and for Windows the functions from the WindowsUserNotification topic.
We decide which part of the program is executed with the FileMaker Get(SystemPlatform) Platform function if its value is -2 it is a Windows operating system and 1 and 3 are Mac or iOS.
![](/image/Advent24_D17_B1.png)
Under the Apple operating systems, we first create a new reference with UNNotification.New. We can now fill this with life by first setting the title and text that should be displayed in the notification with UNNotification.SetTitle and UNNotification.SetBody. Of course, we always specify the reference in these functions in addition to the values. If we want a sound to be played when the notification is displayed, you can set this with UNNotification.SetSound. We use the default sound here, but you can also specify a different sound. So that the notification is also displayed, we trigger it with UNNotification.Deliver.
If [ Get(SystemPlatform)= 1 or Get(SystemPlatform) = 3 ] # Mac and iOS Set Variable [ $UN ; Value: MBS( "UNNotification.New" ) ] Set Variable [ $r ; Value: MBS( "UNNotification.SetTitle"; $UN; $Title) ] Set Variable [ $r ; Value: MBS("UNNotification.SetBody"; $UN; $Text) ] Set Variable [ $r ; Value: MBS("UNNotification.SetSound"; $UN; "default") ] Set Variable [ $r ; Value: MBS("UNNotification.Deliver"; $UN) ]
![](/image/Advent24_D17_B2.png)
We are now done with the Apple part and come to the Windows version. Here we must first initialize the notification system. Here we have to specify which application we want to use, followed by the company name, the surname and the version information. After we have initialized this, we can also create a new working environment here with WindowsUserNotification.NewNotification. We can then set the content of this notification. Let's start with the icon that should be next to the text. This will be our monkey. Since the WindowsUserNotification.SetImagePath requires a path, we write our monkey file in the temporary folder, as we have already seen in another door and then pass the finished path to the function. Just as with the Mac version, we also want to specify the title and text here. In contrast to the Apple version, here we not have title and text, but can also specify two further subordinate texts if required. To do this, we enter an index in the WindowsUserNotification.SetText function next to the reference and the text, which can be in the range between 0 and 3. The smaller the index, the higher up the text is. We take index 0 for the title and index 1 for the text. Now that we have set the texts, we also want to trigger this notification with WindowsUserNotification.ShowNotification.
Else If [ Get(SystemPlatform)= -2 ] # Windows Set Variable [ $r ; Value: MBS( "WindowsUserNotification.Initialize"; "FileMaker"; "Test"; "test"; "test"; "1.0") ] Set Variable [ $UN ; Value: MBS( "WindowsUserNotification.NewNotification" ) ] Set Variable [ $Temp ; Value: MBS("Folders.UserTemporary") ] Set Variable [ $Name ; Value: "ChristmasMonkey.png" ] Set Variable [ $Path ; Value: MBS("Path.AddPathComponent"; $Temp; $Name) ] Set Variable [ $r ; Value: MBS("Files.WriteFile"; $$Overlay_Image; $Path) ] Set Variable [ $r ; Value: MBS( "WindowsUserNotification.SetImagePath"; $UN; $Path ) ] Set Variable [ $r ; Value: MBS( "WindowsUserNotification.SetText"; $UN; 0; $Title ) ] Set Variable [ $r ; Value: MBS( "WindowsUserNotification.SetText"; $UN; 1; $Text ) ] Set Variable [ $r ; Value: MBS( "WindowsUserNotification.ShowNotification"; $UN) ]
With both variants, whether Mac or Windows, we have to think about their release, as we have worked with references.
Our monkey can now keep an eye on the days and is well prepared. We'll see you again tomorrow, until then I wish you a relaxing Advent.
![]() |
||
16 👈 | 17 of 24 | 👉 18 |
![Claris FileMaker Plugin](/images/fmplugin17.jpg)