Module: Jamf::Client::ManagementAction
- Included in:
- Jamf::Client
- Defined in:
- lib/jamf/client/management_action.rb
Overview
Module for working with the Management Action.app, which is an interface to the Notification Center This should be extended into Jamf::Client
Constant Summary collapse
- MGMT_ACTION =
The Pathname to the Management Action executable
SUPPORT_BIN_FOLDER + 'Management Action.app/Contents/MacOS/Management Action'
Instance Method Summary collapse
-
#force_alerts ⇒ Object
Skipping all the force-alerts stuff until we figure out cleaner ways to do it in 10.13+ The plan is to be able to make the NotificationCenter notification be an 'alert' (which stays visible til the user clicks) or a 'banner' (which vanishes in a few seconds), regardless of the user's setting in the NC prefs.
-
#management_action(msg, title: nil, subtitle: nil, delay: 0) ⇒ Object
(also: #nc_notify)
class Methods.
- #restore_alerts(orig_flags) ⇒ Object
-
#set_mgmt_action_ncprefs_flags(user, flags, hup: true) ⇒ Integer
set the NotificationCenter option flags for a user flags = an integer.
Instance Method Details
#force_alerts ⇒ Object
Skipping all the force-alerts stuff until we figure out cleaner ways to do it in 10.13+ The plan is to be able to make the NotificationCenter notification be an 'alert' (which stays visible til the user clicks) or a 'banner' (which vanishes in a few seconds), regardless of the user's setting in the NC prefs.
68 69 70 71 72 73 74 75 76 |
# File 'lib/jamf/client/management_action.rb', line 68 def force_alerts orig_flags = {} console_users.each do |user| orig_flags[user] = set_mgmt_action_ncprefs_flags user, NC_ALERT_STYLE_FLAGS, hup: false end system HUP_NOTIF_CTR_CMD unless orig_flags.empty? sleep 1 orig_flags end |
#management_action(msg, title: nil, subtitle: nil, delay: 0) ⇒ Object Also known as: nc_notify
class Methods
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jamf/client/management_action.rb', line 49 def management_action(msg, title: nil, subtitle: nil, delay: 0) raise Jamf::InvalidDataError, 'delay: must be a non-negative integer.' unless delay.is_a?(Integer) && delay > -1 cmd = Shellwords.escape MGMT_ACTION.to_s cmd << " -message #{Shellwords.escape msg.to_s}" cmd << " -title #{Shellwords.escape title.to_s}" if title cmd << " -subtitle #{Shellwords.escape subtitle.to_s}" if subtitle cmd << " -deliverydelay #{Shellwords.escape delay}" if delay > 0 `#{cmd} 2>&1` end |
#restore_alerts(orig_flags) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/jamf/client/management_action.rb', line 78 def restore_alerts(orig_flags) orig_flags.each do |user, flags| set_mgmt_action_ncprefs_flags user, flags, hup: false end system HUP_NOTIF_CTR_CMD unless orig_flags.empty? end |
#set_mgmt_action_ncprefs_flags(user, flags, hup: true) ⇒ Integer
set the NotificationCenter option flags for a user flags = an integer.
Doesn't seem to work in 10.13, so ignore this for now.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/jamf/client/management_action.rb', line 92 def set_mgmt_action_ncprefs_flags(user, flags, hup: true) plist = Pathname.new "/Users/#{user}/Library/Preferences/#{NCPREFS_DOMAIN}.plist" prefs = JSS.parse_plist plist mgmt_action_setting = prefs['apps'].select { |a| a['bundle-id'] == MGMT_ACTION_BUNDLE_ID }.first if mgmt_action_setting orig_flags = mgmt_action_setting['flags'] mgmt_action_setting['flags'] = flags else orig_flags = flags prefs['apps'] << { 'bundle-id' => MGMT_ACTION_BUNDLE_ID, 'flags' => flags } end plist.open('w') { |f| f.write JSS.xml_plist_from(prefs) } system HUP_NOTIF_CTR_CMD if hup orig_flags end |