Giter VIP home page Giter VIP logo

notifier's Introduction

Licensed under the Apache License, Version 2.0 Copyright 2024 Jamf LTD

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Notifier

Alert

Notifier is a Swift app which can post alert or banner notifications on macOS 10.15+ clients.

Notifications are delivered via the UserNotifications Framework

Usage

Basic Usage

OVERVIEW: Notifier 3.1: Posts alert or banner notifications.

USAGE: --type <alert/banner> --message <some message> <options>
       --type <alert/banner> --remove prior <some message> <options>
       --type <alert/banner> --remove all
       --rebrand <path to image>

OPTIONS:
  --type <type>           alert or banner - REQUIRED.

  --message <message>     The notifications message.

  --messageaction <messageaction>
                          The action to be performed under the users account
                          when the message is clicked.

                          • Passing 'logout' will prompt the user to logout.
                          • If passed a single item, this will be launched via:
                          /usr/bin/open
                          • More complex commands can be passed, but the 1st
                          argument needs to be a binaries path.

                          For example: "/usr/bin/open" will work, "open" will
                          not.

  --messagebutton <messagebutton>
                          Adds a button to the message, with the label being
                          what is passed.

  --messagebuttonaction <messagebuttonaction>
                          The action to be performed under the users account
                          when the optional message button is clicked.

                          • Passing 'logout' will prompt the user to logout.
                          • If passed a single item, this will be launched via:
                          /usr/bin/open
                          • More complex commands can be passed, but the 1st
                          argument needs to be a binaries path.

                          For example: "/usr/bin/open" will work, "open" will
                          not.

  --rebrand <rebrand>     Requires root privileges and that the calling process
                          needs either Full Disk Access (10.15+) or at a
                          minimum App Management (macOS 13+) permissions, as
                          well as the notifying applications being given
                          permission to post to Notification Center. Any of
                          these permissions can be granted manually, but
                          ideally via PPPCP's delivered via an MDM.

                          If successful and someone is logged in, Notification
                          Center is restarted.

  --remove <remove>       "prior" or "all". If passing "prior", the full
                          message will be required too. Including all passed
                          flags.

  --sound <sound>         The sound to play when notification is delivered.
                          Pass "default" for the default macOS sound, else the
                          name of a sound in /Library/Sounds or
                          /System/Library/Sounds.

                          If the sound cannot be found, macOS will use the
                          "default" sound.

  --subtitle <subtitle>   The notifications subtitle.

  --title <title>         The notifications title.

  --verbose               Enables logging of actions. Check console for
                          'Notifier' messages.

  --help                  Show help information.

Examples

The below aim to give you an idea of what so the various notification options look like, across macOS versions as well as Light and Dark mode.

As you can see, some of the behaviour and appearence is OS dependent.

Example 1 This example shows a basic banner notification.

macOS 10.15.7 - Light Mode macOS 14.3 - Dark mode
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type banner --message "message"

Example 2 This example shows a basic alert notification.

macOS 10.15.7 - Light Mode macOS 14.3 - Dark mode
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message "message" --messagebutton "Logout" --messagebuttonaction "Logout"

Example 3 This example shows both alert & banner notifications, (sleep used for the example gif, not needed in use but below for completeness sake).

macOS 10.15.7 - Light Mode macOS 14.3 - Dark mode
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message "Please Logout" --messagebutton "Logout"  --messagebuttonaction "logout" --title "Logout";
/bin/sleep 2;
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type banner --message "👋" --title "Notification"

Example 4 This example shows selective remove of a delivered notificaition via --remove prior. Where applicable this would also remove notifications from within Notification Center itself.

macOS 10.15.7 - Light Mode macOS 14.3 - Dark mode
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message 'Look at me!!';
/bin/sleep 2; 
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message "message" --messagebutton "Logout";
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message 'Look at me!!' --remove prior

Example 5 This example shows removal of all alert notifications and also the differences of delivery of alert notifications across macOS versions, additionally this removes any prior delivered notificaions from Notification Center. Sleep used for the example gif, not needed in use but below for completeness sake.

macOS 10.15.7 - Light Mode macOS 14.3 - Dark mode
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message message;
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message message1;
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message message2;
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message message3;
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message message4;
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message message5;
/bin/sleep 5;
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --remove all

Example 6 This example shows Notifier 3.0+'s --rebrand argument in use, this allows for rebranding of Notifier without having to venture into Xcode etc.

macOS 10.15.7 - Light Mode macOS 14.3 - Dark mode
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message "message";
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type banner --message "message";
/bin/sleep 2;
/usr/bin/sudo /Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --rebrand /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ErasingIcon.icns;
/bin/sleep 2;
/usr/bin/sudo /Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type banner --message "message";
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --rebrand /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericFileServerIcon.icns;
/bin/sleep 2;
/usr/bin/sudo /Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type banner --message "message";
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --rebrand /Applications/Utilities/Notifier.app/Contents/Resources/AppIcon.icns;
/bin/sleep 2;
/Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type banner --message "message"

Deployment

PPPC

It's recommended that the below profile is recommended to be deployed before Notfier itself, to UAMDM devices. (https://github.com/dataJAR/Notifier/blob/master/profile/Allow%20Notifier%20Notifications.mobileconfig)

This will allow Notifier to post Notifications without prompting the user to allow.

Additionally, if you're looking to make use of the --rebrand flag the calling process needs either Full Disk Access/SystemPolicyAllFiles (10.15+) or at a minimum App Management/SystemPolicyAppBundles (macOS 13+) permissions, as well as the notifying applications being given permission to post to Notification Center.

Any of these permissions can be granted manually, but ideally via PPPCP's delivered via an MDM.

PKG

PKG's will be supplied for every release, & can be found in the releases section.

Flow

The below is the advised deployment flow for Notifier.

  1. If rebranding - deploy a PPPC for your management tool of choice, granting either Full Disk Access/SystemPolicyAllFiles (10.15+) or App Management/SystemPolicyAppBundles (macOS 13+).
  2. Deploy the Notications PpPC to UAMDM devices
  3. Deploy the latest Notifier PKG
  4. If rebranding - deploy the image to use when rebranding.
  5. if rebranding - deploy a script or payload free package etc which rebrands Notifier via your management tool. This needs to be down with admin/root privileges.

How it works

The main Notifier.app parses arguments passed to it (via Argument Parser, and then posts the parsed argument to the two notifying applications included with the the /Contents/Helpers folder of Notifier.app:

/Applications/Utilities/Notifier.app/Contents/Helpers/
                                                      Notifier - Alerts.app
                                                      Notifier - Notifications.app

Additionally the Notifier.app also checks tha Notification Center is running, & runs the notifying apps in the user context.

The notifying apps (/Applications/Utilities/Notifier.app/Contents/Helpers/Notifier - Alerts.app and /Applications/Utilities/Notifier.app/Contents/Helpers/Notifier - Notifications.app) both post notifications via the UserNotifications Framework.

Miscellaneous

Resetting Notifications Center

The below should reset Notifications Center, but please test & submit a PR with a better method as applicable.

  1. /bin/rm -rf $(getconf DARWIN_USER_DIR)/com.apple.notificationcenter/*
  2. Logout & then log back in, or:
  • For macOS 10.15+: /usr/bin/killall "NotificationCenter"
  1. Test the Notifier once more

FAQs

Q1: Why start at version 2?

A1: At dataJAR, we already had a v1 "Notifier" app deployed.

Q2: How can you post both banner & alert notifications?

A2: See How it works

Q3: The users are being prompted to allow.. help!

A3: This can be due to a few things:

  1. Was the notifications profile installed? If not, install.
  2. Is the device under UAMDM? If not, check with your MDM vendor on making the device UAMDM. Then try again & maybe reinstall the profile once under UAMDM.
  3. Did you change the Bundle ID of either the Alert or Banner applications? If so you'll need to amend the notifications profile accordingly.

Q4: Is that logo magen...

A4: No, it's a shade of pink...

Q5: Banner or Notifications?

A5: The temporary notifications are referred to as "banner" notifications in Apple's documentation, but it seems that most folks call them "Notifications" with the persistent notifications being referred to as alerts by folks as well as within Apple's documentation.

Q6: I'm seeing alerts when expecting banner notifications, & vice versa

A6: Check the Notification settings within System Preferences/System Settings, it's possible that the incorrect option has been selected or set via a profile.

Q7: --remove prior, didn't clear my last message.

A7: Make sure you pass EXACTLY the same message to be cleared.

Q8: I've rebranded, but the old icon is being shown..

A8: Please reset Notification Center as per the Resetting Notifications Center, then try again.

Q9: Does rebranding work when no one is logged in?

A9: Yep, and no restart of Notification Center is needed.

Q10 Why are notifcations all of a sudden showing a prohibted sign across the icon?

A10 This is a macOS issue that has goes back some years, to resolve either restart Notification Center or the Mac.

Alternatives

The below projects can be used instead of Notifier & were very much instrumental in Notifiers creation

Alert Notifications

Yo

Banner Notifications

Terminal Notifier

notifier's People

Contributors

macmule avatar davidnorris78 avatar kevinmcox avatar chalcahuite avatar tsparr avatar ehemmete avatar

Stargazers

Danbo Duan avatar  avatar Mike Solin avatar Yasuyuki Oka avatar Alexander Zizzo avatar  avatar r3plikent avatar ilove007 avatar neogemic avatar Post Writer avatar  avatar  avatar Brad Clare avatar Kan avatar Christian Winther avatar Manikandan R avatar  avatar  avatar  avatar Reginald Essien avatar V Duo avatar Kay avatar 小书僮 avatar Joe Selway avatar  avatar Victor Bottacco avatar Niko Krämer avatar Ryon Riley avatar Marcin Wisniowski avatar  avatar Michael Permann avatar  avatar Robert Clover avatar Easton avatar Andrew Worth Carson avatar Kevin W avatar  avatar buzai avatar Herby Gillot avatar Manoj Karthick avatar CardinalDeVille avatar Joe Harden avatar Stephen Boyle avatar Martin Friedrich avatar Seb Fischer avatar Sammy Farida avatar stimulated avatar oxxd avatar Matthew Warren avatar Eric Summers avatar  avatar Tobias Almén avatar Tobias Morrison avatar  avatar  avatar Luke Hamburg avatar  avatar Matin Sasaluxanon avatar  avatar Dustin J. Landgraf avatar  avatar Søren Theilgaard avatar Jarad Alderson avatar Adam W avatar Macninja avatar  avatar eg avatar Jens Malessa avatar  avatar Security Generation avatar Scripts and Things avatar Jeremy Chabernaud avatar Robby Barnes avatar  avatar  avatar Manuel Brotz avatar M B avatar Elliot Jordan avatar Oliver Busch avatar  avatar Ben Perry avatar Stephen Johnson avatar  avatar Thomas avatar Joseph Chilcote avatar Perren Smith avatar Jovins avatar LaoHan avatar  avatar Alex Sherbakov avatar mono — Masayuki Ono avatar kour1er avatar  avatar Johan McGwire avatar Paul Galow avatar Kenny Botelho avatar Jared avatar Luis Lugo avatar  avatar Tristan Thomas avatar

Watchers

Jens Malessa avatar Perren Smith avatar James Cloos avatar Ben Perry avatar Luke Hamburg avatar  avatar James Ridsdale avatar Robert Harkess avatar  avatar Kevin W avatar Callum Dean avatar Neil Martin avatar  avatar Paul Cossey avatar Keith Beeby avatar Sanchi avatar  avatar Matin Sasaluxanon avatar  avatar  avatar

notifier's Issues

Close button missing on macOS 10.15 for alert notification

Calling notifier with alert type notification has a different visual result on two tested OSes. Using the following example:

notifier --type alert --title "Company" --subtitle "Communication" --message "macOS Big Sur" --messagebutton "Info" --messagebuttonaction "https://www.apple.com/macos/big-sur-preview/"

macOS 10.13.6 - Shows a Close and Info (action) button.
macOS 10.15.6 - Shows only the Info (action) button.

open app not working under macOS 11.6

under macOS 11.6. using /Applications/Utilities/Notifier.app/Contents/MacOS/Notifier --type alert --message "TEST" --messageaction "/Applications/Safari.app/" does not open the app when clicking the notification.
no problem with 11.5.2
i have noticed the same misbehavior with https://github.com/sheagcraig/yo , so it is probably a general problem with 11.6 ?

Swift Compile Error

Was attempting to build with my signing cert and new icons but ran in to a swift compile error. On macOS 12.0.1 - M1 - Xcode 13.1

SwiftPM - Sources - Basic - Await.swift - await

Line 18:

Value of type '(@escaping (Result<T, ErrorType>) -> Void) -> Void' has no member 'dematerialize'

code block referenced:

public func await<T, ErrorType>(_ body: (@escaping (Result<T, ErrorType>) -> Void) -> Void) throws -> T {
    return try await(body).dematerialize()
}

looks to be a dependency issue?

FR: "More info" window

Notifications are really limited in the amount of information that they are able to present. Sometimes, it is needed to have the "action" open up a new window with more info on whatever the alert was about.

There are a couple of existing methods that could be used to display such a window: JamfHelper, DEPNotify, etc. However, they are either aimed at a different feature set, or are limited in customisation options, or both. Additionally, such an approach requires management of a second tool, increasing complexity.

It would be really useful to have a simple "More info" window that used the same branding/style as the notification, triggered by the Action, and which could display a text-based message. Bonus points if it supports markdown!

I appreciate that this is a significant scope creep, so I'm not really expecting it to be accepted lol. But if Ben (or anyone else) is bored in lockdown, I (for one) would really appreciate this. If I only had enough Swift knowledge (or the time to learn) I'd give it a go myself...

BS b9 - ERROR: Notification Center is not running..

com.apple.notificationcenterui2 has been the bundle ID of Notification Centre up to B9.. now it’s com.apple.notificationcenteru, which is the same as any macOS before..

So can revert the changes for this and the issue with the if #available API and BS is now moot as not needed for BS checking anymore.

Banner runs once only

Just downloaded the project, updated with my signing cert and icons according to the instructions, and built a test version. It ran a banner once, which appears for a second & immediately disappears, but subsequent runs do not show anything. I switched to an alert message, and the same thing happened.

Running macOS 10.15.6. --verbose doesn't seem to show anything errors, it seems to think it ran. Running with sudo does not have an effect either.

➜ /Users/chkemp/Documents/Software\ Releases/Notifier/Notifier\ 2020-07-31\ 11-13-09/Products/Applications/Notifier.app/Contents/MacOS/Notifier --type alert --message "MacIT Notification banner" --verbose
2020-07-31 11:29:30.301 Notifier[27364:1252648] Notifier Log: notifier - verbose enabled
2020-07-31 11:29:30.301 Notifier[27364:1252648] Notifier Log: notifier - message
2020-07-31 11:29:30.301 Notifier[27364:1252648] Notifier Log: notifier - notifierArgsArray - (
"--verbose",
"--message",
"MacIT Notification banner"
)
2020-07-31 11:29:30.301 Notifier[27364:1252648] Notifier Log: notifier - type - alert
2020-07-31 11:29:30.302 Notifier[27364:1252648] Notifier Log: notifier - path - /Users/chkemp/Documents/Software Releases/Notifier/Notifier 2020-07-31 11-13-09/Products/Applications/Notifier.app/Contents/Resources/alert/MacIT - Alerts.app/Contents/MacOS/MacIT - Alerts
2020-07-31 11:29:30.302 Notifier[27364:1252648] Notifier Log: notifier - running as user
2020-07-31 11:29:30.302 Notifier[27364:1252648] Notifier Log: notifier - task.launchPath - Optional("/Users/chkemp/Documents/Software Releases/Notifier/Notifier 2020-07-31 11-13-09/Products/Applications/Notifier.app/Contents/Resources/alert/MacIT - Alerts.app/Contents/MacOS/MacIT - Alerts")
2020-07-31 11:29:30.302 Notifier[27364:1252648] Notifier Log: notifier - task.arguments - Optional(["--verbose", "--message", "MacIT Notification banner"])
2020-07-31 11:29:30.302 Notifier[27364:1252648] Notifier Log: notifier - launch
2020-07-31 11:29:30.425 Notifier[27364:1252648] Notifier Log: notifier - complete

"Final Updates"

I see the last updates are labelled "Final Updates" has this project been abandoned?

Passing terminal commands to --messageaction

I'd like to be able to pass terminal commands to --messageaction in much the same way that you can with Yo's -B / --bash-action.

I can't seem to work out how to get the correct syntax to make this happen with the available flags in Notifier. Is this something that's not available, or am I doing it wrong!

open with arguments

I want to do something like that:
./Notifier --type alert --message "My Message" --messagebutton "Open" --messagebuttonaction "/System/Applications/Utilities/Terminal.app ~/test.sh"

Unfortunately everything this doesn't work. It would also be nice to be able to pass option to open, like:

Options: 
      -a                    Opens with the specified application.
      -b                    Opens with the specified application bundle identifier.
      -e                    Opens with TextEdit.
      -t                    Opens with default text editor.
      -f                    Reads input from standard input and opens with TextEdit.
      -F  --fresh           Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.
      -R, --reveal          Selects in the Finder instead of opening.
      -W, --wait-apps       Blocks until the used applications are closed (even if they were already running).
          --args            All remaining arguments are passed in argv to the application's main() function instead of opened.
      -n, --new             Open a new instance of the application even if one is already running.
      -j, --hide            Launches the app hidden.
      -g, --background      Does not bring the application to the foreground.
      -h, --header          Searches header file locations for headers matching the given filenames, and opens them.
      -s                    For -h, the SDK to use; if supplied, only SDKs whose names contain the argument value are searched.
                            Otherwise the highest versioned SDK in each platform is used.
      -u, --url URL         Open this URL, even if it matches exactly a filepath
      -i, --stdin  PATH     Launches the application with stdin connected to PATH; defaults to /dev/null
      -o, --stdout PATH     Launches the application with /dev/stdout connected to PATH; 
          --stderr PATH     Launches the application with /dev/stderr connected to PATH to
          --env    VAR      Add an enviroment variable to the launched process, where VAR is formatted AAA=foo or just AAA for a null string value.

Not working on 10.14.6 No info.plist or no NSPrincipalClass

Running on Mac os 10.14.6 gives me an error:
"/applications/utilities/notifier.app/contents/resources/alert/Notifier - Alerts.app/contents/macos/Notifier - Alerts" --message "test"
2020-12-21 12:26:09.225 Notifier - Alerts[3531:27450] No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting

If i cd in to the folder and issue "./Notifier - Alerts" --message "test" I get a notification.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.