Skip to content

Commit

Permalink
swiftDialog Notifications (0.0.4)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan K. Snelson <[email protected]>
  • Loading branch information
dan-snelson committed Jan 28, 2024
1 parent 7f3de02 commit f34f6bc
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 87 deletions.
10 changes: 5 additions & 5 deletions swiftDialog Notifications/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Notifications via swiftDialog
# Actionable Notifications via swiftDialog (2.4.0)

> A pair of scripts to help Jamf Pro admins easily display custom branded macOS Notifications

## Background

One of the more welcome features of swiftDialog 2.0 are macOS Notifications and when combined with Script Parameters, Jamf Pro administrators can easily display custom branded macOS Notifications to their users.
One of the more welcome features of swiftDialog 2.4.0 is actionable macOS Notifications and when combined with Script Parameters, Jamf Pro administrators can easily display custom-branded, actionable macOS Notifications to their users.

![Custom Branded Notification](images/custom_branded_notification.png)
![Custom Branded Notification](images/notification_script_%20parameters.png)
![Custom Branded Notification](images/sd_Notifications-00001.png))
![Custom Branded Notification](images/sd_Notifications-00002.png))


[Continue reading …](https://snelson.us/2023/03/swiftdialog-notifications/)
[Continue reading …](https://snelson.us/)

---

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
253 changes: 171 additions & 82 deletions swiftDialog Notifications/swiftDialog Notifications.bash
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/bin/bash
#!/bin/zsh
# shellcheck shell=bash
# shellcheck disable=SC2317

####################################################################################################
#
# ABOUT
#
# swiftDialog Notifications
#
# See: https://snelson.us/2023/03/swiftdialog-notifications/
# See: https://snelson.us/?s=swiftdialog
#
####################################################################################################
#
# HISTORY
#
# Version 0.0.1, 14-Nov-2022, Dan K. Snelson (@dan-snelson)
# - Original proof-of-concept version
#
# Version 0.0.3, 16-Mar-2023, Dan K. Snelson (@dan-snelson)
# - Updates from 'swiftDialog Pre-install.bash'
# - Matched version number of 'swiftDialog Pre-install.bash'
# Version 0.0.4, 28-Jan-2024, Dan K. Snelson (@dan-snelson)
# - Updated for swiftDialog v2.4.0
#
####################################################################################################

Expand All @@ -32,62 +31,163 @@
# Global Variables
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

scriptVersion="0.0.3"
export PATH=/usr/bin:/bin:/usr/sbin:/sbin

# Script Version & Client-side Log
scriptVersion="0.0.4"
scriptLog="/var/tmp/org.churchofjesuschrist.log"

# swiftDialog Binary & Log
dialogBinary="/usr/local/bin/dialog"
dialogNotificationLog=$( mktemp -u /var/tmp/dialogNotificationLog.XXXX )

# Current logged-in user
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
dialogApp="/usr/local/bin/dialog"
dialogNotificationLog=$( mktemp /var/tmp/dialogNotificationLog.XXX )
scriptLog="${4:-"/var/tmp/org.churchofjesuschrist.log"}"

if [[ -n ${5} ]]; then titleoption="--title"; title="${5}"; fi
if [[ -n ${6} ]]; then subtitleoption="--subtitle"; subtitle="${6}"; fi
if [[ -n ${7} ]]; then messageoption="--message"; message="${7}"; fi


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Jamf Pro Script Parameters
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Parameter 4: Title
title="${4:-"Title [Parameter 4]"}"

# Parameter 5: Message
message="${5:-"Message [Parameter 5]"}"

# Parameter 6: Button 1 Text
if [[ -n ${6} ]]; then button1TextOption="--button1text"; button1text="${6}"; fi

# Parameter 7: Button 1 Action
if [[ -n ${7} ]]; then button1ActionOption="--button1action"; button1action="${7}"; fi

# Parameter 8: Button 2 Text
if [[ -n ${8} ]]; then button2TextOption="--button2text"; button2text="${8}"; fi

# Parameter 9: Button 2 Action
if [[ -n ${9} ]]; then button2ActionOption="--button2action"; button2action="${9}"; fi



# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Organization Variables
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Script Human-readable Name
humanReadableScriptName="swiftDialog Notifications"

# Organization's Script Name
organizationScriptName="sdNotify"



####################################################################################################
#
# Pre-flight Checks
# Functions
#
####################################################################################################

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Client-side Logging
# Client-side Logging
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

if [[ ! -f "${scriptLog}" ]]; then
touch "${scriptLog}"
fi
function updateScriptLog() {
echo "${organizationScriptName} ($scriptVersion): $( date +%Y-%m-%d\ %H:%M:%S ) - ${1}" | tee -a "${scriptLog}"
}

function preFlight() {
updateScriptLog "[PRE-FLIGHT] ${1}"
}

function logComment() {
updateScriptLog " ${1}"
}

function notice() {
updateScriptLog "[NOTICE] ${1}"
}

function info() {
updateScriptLog "[INFO] ${1}"
}

function errorOut(){
updateScriptLog "[ERROR] ${1}"
}

function error() {
updateScriptLog "[ERROR] ${1}"
let errorCount++
}

function warning() {
updateScriptLog "[WARNING] ${1}"
let errorCount++
}

function fatal() {
updateScriptLog "[FATAL ERROR] ${1}"
exit #1
}

function quitOut(){
updateScriptLog "[QUIT] ${1}"
}



# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Client-side Script Logging Function
# Quit Script (thanks, @bartreadon!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

function updateScriptLog() {
echo -e "$( date +%Y-%m-%d\ %H:%M:%S ) - ${1}" | tee -a "${scriptLog}"
function quitScript() {

notice "*** QUITTING ***"

# Remove dialogNotificationLog
if [[ -f "${dialogNotificationLog}" ]]; then
logComment "Removing ${dialogNotificationLog}"
rm "${dialogNotificationLog}"

fi

logComment "Goodbye!"
exit "${1}"

}



####################################################################################################
#
# Pre-flight Checks
#
####################################################################################################

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Current Logged-in User Function
# Pre-flight Check: Client-side Logging
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

function currentLoggedInUser() {
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
updateScriptLog "PRE-FLIGHT CHECK: Current Logged-in User: ${loggedInUser}"
}
if [[ ! -f "${scriptLog}" ]]; then
touch "${scriptLog}"
if [[ -f "${scriptLog}" ]]; then
preFlight "Created specified scriptLog: ${scriptLog}"
else
fatal "Unable to create specified scriptLog '${scriptLog}'; exiting.\n\n(Is this script running as 'root' ?)"
fi
else
preFlight "Specified scriptLog '${scriptLog}' exists; writing log entries to it"
fi



# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Logging Preamble
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

updateScriptLog "\n\n###\n# swiftDialog Notifications (${scriptVersion})\n# https://snelson.us\n###\n"
updateScriptLog "PRE-FLIGHT CHECK: Initiating …"
preFlight "\n\n###\n# $humanReadableScriptName (${scriptVersion})\n# https://snelson.us/\n###\n"
preFlight "Initiating …"



Expand All @@ -96,8 +196,7 @@ updateScriptLog "PRE-FLIGHT CHECK: Initiating …"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

if [[ $(id -u) -ne 0 ]]; then
updateScriptLog "PRE-FLIGHT CHECK: This script must be run as root; exiting."
exit 1
fatal "This script must be run as root; exiting."
fi


Expand All @@ -106,87 +205,77 @@ fi
# Pre-flight Check: Validate logged-in user
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

currentLoggedInUser
if [[ -z "${loggedInUser}" || "${loggedInUser}" == "loginwindow" ]]; then
updateScriptLog "PRE-FLIGHT CHECK: No user logged-in; exiting"
exit 1
fatal "No user logged-in; exiting"
fi



# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Complete
# Pre-flight Check: Validate Script Parameters
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

updateScriptLog "PRE-FLIGHT CHECK: Complete"
if [[ -z "${title}" || "${title}" == "Title [Parameter 4]" ]] ; then

warning "Title [Parameter 4] is either empty or NOT set; displaying instructions …"

title="Title [Parameter 4]: swiftDialog Wiki"

####################################################################################################
#
# Functions
#
####################################################################################################
message="Message [Parameter 5]: Have you checked Bart's Wiki?"

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Quit Script (thanks, @bartreadon!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
button1TextOption="--button1text"
button1text="Button 1 Text [Parameter 6]: No"

function quitScript() {
button1ActionOption="--button1action"
button1action="https://github.com/swiftDialog/swiftDialog/wiki"

updateScriptLog "Quitting …"
button2TextOption="--button2text"
button2text="Button 2 Text [Parameter 8]: Yes"

# Remove dialogNotificationLog
if [[ -e ${dialogNotificationLog} ]]; then
updateScriptLog "Removing ${dialogNotificationLog}"
rm "${dialogNotificationLog}"
fi
button2ActionOption="--button2action"
button2action="https://snelson.us/?s=swiftdialog"

updateScriptLog "Goodbye!"
exit "${1}"

}
else

updateScriptLog "Parameter 4, \"title,\" is populated; proceeding ..."

fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Validate Script Parameters
# Pre-flight Check: Complete
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

if [[ -z "${title}" ]] ; then

updateScriptLog "Parameter 5 is NOT populated; displaying instructions …"
preFlight "Complete!"

titleoption="--title"
title="Title [Parameter 5] goes here"

subtitleoption="--subtitle"
subtitle="Subtitle [Parameter 6] goes here"

messageoption="--message"
message="Message [Parameter 7] goes here"

else

updateScriptLog "Parameters 5, \"title,\" is populated; proceeding ..."

fi


####################################################################################################
#
# Program
#
####################################################################################################

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Display Notification
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

updateScriptLog "Title: ${title}"
updateScriptLog "Subtitle: ${subtitle}"
updateScriptLog "Message: ${message}"
notice "*** DISPLAY NOTIFICATION ***"

logComment "Title (Parameter 4): ${title}"
logComment "Message (Parameter 5): ${message}"

if [[ -n "${button1text}" ]]; then logComment "Button 1 Text (Parameter 6): ${button1text}" ; fi
if [[ -n "${button1action}" ]]; then logComment "Button 1 Action (Parameter 7): ${button1action}" ; fi
if [[ -n "${button2text}" ]]; then logComment "Button 2 Text (Parameter 8): ${button2text}" ; fi
if [[ -n "${button2action}" ]]; then logComment "Button 2 Action (Parameter 9): ${button2action}" ; fi

${dialogApp} \
${dialogBinary} \
--notification \
"${titleoption}" "${title}" \
"${subtitleoption}" "${subtitle}" \
"${messageoption}" "${message}" \
--title "${title}" \
--message "${message}" \
"${button1TextOption}" "${button1text}" \
"${button1ActionOption}" "${button1action}" \
"${button2TextOption}" "${button2text}" \
"${button2ActionOption}" "${button2action}" \
--commandfile "$dialogNotificationLog}"


Expand Down

0 comments on commit f34f6bc

Please sign in to comment.