|
| 1 | +#!/bin/zsh |
| 2 | + |
| 3 | +# Support App Extension - Jamf Pro Last Check-In Time |
| 4 | +# |
| 5 | +# |
| 6 | +# Copyright 2022 Root3 B.V. All rights reserved. |
| 7 | +# |
| 8 | +# Support App Extension to get the Jamf Pro Last Check-In Time and publish to |
| 9 | +# Extension A. |
| 10 | +# |
| 11 | +# REQUIREMENTS: |
| 12 | +# - Jamf Pro Binary |
| 13 | +# |
| 14 | +# THE SOFTWARE IS PROVIDED BY ROOT3 B.V. "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 | +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO |
| 17 | +# EVENT SHALL ROOT3 B.V. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 18 | +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR |
| 19 | +# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + |
| 21 | +# ------------------ edit the variables below this line ------------------ |
| 22 | + |
| 23 | +# Enable 24 hour clock format. 12 hour clock enabled by default |
| 24 | +twenty_four_hour_format="true" |
| 25 | + |
| 26 | +# --------------------- do not edit below this line ---------------------- |
| 27 | + |
| 28 | +# Support App preference plist |
| 29 | +preference_file_location="/Library/Preferences/nl.root3.support.plist" |
| 30 | + |
| 31 | +# Start spinning indicator |
| 32 | +defaults write "${preference_file_location}" ExtensionLoadingA -bool true |
| 33 | + |
| 34 | +# Replace value with placeholder while loading |
| 35 | +defaults write "${preference_file_location}" ExtensionValueA -string "KeyPlaceholder" |
| 36 | + |
| 37 | +# Keep loading effect active for 0.5 seconds |
| 38 | +sleep 0.5 |
| 39 | + |
| 40 | +# Get last Jamf Pro check-in time from jamf.log |
| 41 | +last_check_in_time=$(grep "Checking for policies triggered by \"recurring check-in\"" "/private/var/log/jamf.log" | tail -n 1 | awk '{ print $2,$3,$4 }') |
| 42 | + |
| 43 | +# Convert last Jamf Pro check-in time to epoch |
| 44 | +last_check_in_time_epoch=$(date -j -f "%b %d %T" "${last_check_in_time}" +"%s") |
| 45 | + |
| 46 | +# Convert last Jamf Pro epoch to something easier to read |
| 47 | +if [[ "${twenty_four_hour_format}" == "true" ]]; then |
| 48 | + # Outputs 24 hour clock format |
| 49 | + last_check_in_time_human_reable=$(date -r "${last_check_in_time_epoch}" "+%A %H:%M") |
| 50 | +else |
| 51 | + # Outputs 12 hour clock format |
| 52 | + last_check_in_time_human_reable=$(date -r "${last_check_in_time_epoch}" "+%A %I:%M %p") |
| 53 | +fi |
| 54 | + |
| 55 | +# Write output to Support App preference plist |
| 56 | +defaults write "${preference_file_location}" ExtensionValueA -string "${last_check_in_time_human_reable}" |
| 57 | + |
| 58 | +# Stop spinning indicator |
| 59 | +defaults write "${preference_file_location}" ExtensionLoadingA -bool false |
0 commit comments