Module: Jamf::Client::ManagementAction::ClassMethods
- Defined in:
- lib/jamf/client/management_action.rb
Overview
class Methods
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)
- #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.
76 77 78 79 80 81 82 83 84 |
# File 'lib/jamf/client/management_action.rb', line 76 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
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/jamf/client/management_action.rb', line 57 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
86 87 88 89 90 91 |
# File 'lib/jamf/client/management_action.rb', line 86 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.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/jamf/client/management_action.rb', line 100 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 |