🙆‍♀️

jamfHelper.appを指定した日時にポップアップする

2022/07/12に公開

jamfHelper.appとは

以下のコマンドでボタン付きのモーダルが出せます。
/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -title "タイトル" -description "詳細" -button1 "ボタン"

ボタンを増やしたり、アイコンを付けたり、フルスクリーンにもできます。
詳しくは https://apple.lib.utah.edu/jamfhelper/ を参考にしてください。

LaunchDaemonsとは

特定のユーザーに紐づけられていないバックグラウンドシステムです。
今回は defaults write /path/to/plist コマンドで実行時間などを設定しています。
詳しくは https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html を参考にしてください。

launchctl

launchctl コマンドを使って起動・停止・管理を行います。

launchctl list launchdにロードされているジョブ一覧
launchctl load /path/to/plist launchdを起動する
launchctl unload /path/to/plist launchdを停止する

LaunchDaemonsで特定の日時にjamfHelper.appを実行してZoomに招待する

こんなかんじの通知をだします!
https://twitter.com/bboobbaa/status/1527511032700489728?s=20&t=f5tsQrHG094UnF5NGCnOJg

引数の設定

JamfPro->スクリプト->オプションから4~11までパラメーター設定できます。

    1. 実行日時(2022,4,1,10,0)
    1. タイトル
    1. 詳細
    1. ボタン
    1. ZoomミーティングID
    1. Zoomミーティングパスコード

Zoomを開く

以下のコマンドでZoomミーティングが直接開けます。
open "zoommtg://zoom.us/join?confno=ZoomミーティングID&pwd=Zoomミーティングパスコード"

スクリプトを書く

#!/bin/bash

# 実行日時の配列を取得
IFS=, ARR=(${4})

# すでにnotificationZoomのジョブがあれば削除
RESULT=`launchctl list | grep notificationZoom`
if [[ "$RESULT" =~ "notificationZoom" ]]; then
  launchctl unload /Library/LaunchDaemons/notificationZoom.plist
fi
# plistにnotificationZoomのラベルを付ける
sudo defaults write /Library/LaunchDaemons/notificationZoom.plist Label -string "notificationZoom"
# plistにnotificationZoom.shを実行するように設定する
sudo defaults write /Library/LaunchDaemons/notificationZoom.plist ProgramArguments -array -string /bin/sh -string "/Library/Application Support/JAMF/notificationZoom.sh"
# plistに実行日時を設定する
sudo defaults write /Library/LaunchDaemons/notificationZoom.plist StartCalendarInterval -dict "Year" -integer ${ARR[0]} "Month" -integer ${ARR[1]} "Day" -integer ${ARR[2]} "Hour" -integer ${ARR[3]} "Minute" -integer ${ARR[4]} 
# RunAtLoadを無効にする
sudo defaults write /Library/LaunchDaemons/notificationZoom.plist RunAtLoad -boolean false
# ファイル権限を変更
sudo chown root:wheel /Library/LaunchDaemons/notificationZoom.plist
sudo chmod 644 /Library/LaunchDaemons/notificationZoom.plist
# launchdを起動する
launchctl load /Library/LaunchDaemons/notificationZoom.plist

# jamfHelper.appを起動するnotificationZoom.shを作成
cat << EOF > /Library/Application\ Support/JAMF/notificationZoom.sh
RESULT=\`/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -title "${5}" -description "${6}" -button1 "${7}"\`
if [ \$RESULT == 0 ]; then
  open "zoommtg://zoom.us/join?confno=${8}&pwd=${9}"
  exit
fi
launchctl unload /Library/LaunchDaemons/notificationZoom.plist
rm /Library/LaunchDaemons/notificationZoom.plist
EOF

以上となります!お疲れさまでした!

Discussion