module Jamf::Client::ManagementAction::ClassMethods

class Methods

Public Instance Methods

force_alerts() click to toggle source

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.

   # File lib/jamf/client/management_action.rb
76 def force_alerts
77   orig_flags = {}
78   console_users.each do |user|
79     orig_flags[user] = set_mgmt_action_ncprefs_flags user, NC_ALERT_STYLE_FLAGS, hup: false
80   end
81   system HUP_NOTIF_CTR_CMD unless orig_flags.empty?
82   sleep 1
83   orig_flags
84 end
management_action(msg, title: nil, subtitle: nil, delay: 0) click to toggle source
   # File lib/jamf/client/management_action.rb
57 def management_action(msg, title: nil, subtitle: nil, delay: 0)
58   raise Jamf::InvalidDataError, 'delay: must be a non-negative integer.' unless delay.is_a?(Integer) && delay > -1
59 
60   cmd = Shellwords.escape MGMT_ACTION.to_s
61   cmd << " -message #{Shellwords.escape msg.to_s}"
62   cmd << " -title #{Shellwords.escape title.to_s}" if title
63   cmd << " -subtitle #{Shellwords.escape subtitle.to_s}" if subtitle
64   cmd << " -deliverydelay #{Shellwords.escape delay}" if delay > 0
65   `#{cmd} 2>&1`
66 end
Also aliased as: nc_notify
nc_notify(msg, title: nil, subtitle: nil, delay: 0)
Alias for: management_action
restore_alerts(orig_flags) click to toggle source
   # File lib/jamf/client/management_action.rb
86 def restore_alerts(orig_flags)
87   orig_flags.each do |user, flags|
88     set_mgmt_action_ncprefs_flags user, flags, hup: false
89   end
90   system HUP_NOTIF_CTR_CMD unless orig_flags.empty?
91 end
set_mgmt_action_ncprefs_flags(user, flags, hup: true) click to toggle source

set the NotificationCenter option flags for a user flags = an integer.

Doesn’t seem to work in 10.13, so ignore this for now.

@return [Integer] the original flags, or given flags if no originals.

    # File lib/jamf/client/management_action.rb
100 def set_mgmt_action_ncprefs_flags(user, flags, hup: true)
101   plist = Pathname.new "/Users/#{user}/Library/Preferences/#{NCPREFS_DOMAIN}.plist"
102   prefs = JSS.parse_plist plist
103   mgmt_action_setting = prefs['apps'].select { |a| a['bundle-id'] == MGMT_ACTION_BUNDLE_ID }.first
104   if mgmt_action_setting
105     orig_flags = mgmt_action_setting['flags']
106     mgmt_action_setting['flags'] = flags
107   else
108     orig_flags = flags
109     prefs['apps'] << { 'bundle-id' => MGMT_ACTION_BUNDLE_ID, 'flags' => flags }
110   end
111   plist.open('w') { |f| f.write JSS.xml_plist_from(prefs) }
112   system HUP_NOTIF_CTR_CMD if hup
113   orig_flags
114 end