May-05-2019, 05:49 AM
(This post was last modified: May-05-2019, 05:50 AM by kennethdean2010.)
Ok so the code below just keeps looping with 5 minutes still as an option, does not wait 5 mins either it just keeps looping what am I doing wrong with that counter? I am definately on the right track thanks to you SheeppOSU!!! :) The Jamf Helper Gui is displaying multiple times just not as intended.
def display_prompt(): """Displays prompt to allow user to schedule update installation Args: None Returns: (int) defer_seconds: Number of seconds user wishes to defer policy OR None if an error occurs """ #counter to loop through display_prompt X amount of times. cmd = [JAMFHELPER, '-windowType', 'hud', '-title', GUI_WINDOW_TITLE, '-heading', GUI_HEADING, '-icon', GUI_ICON, '-description', GUI_MESSAGE, '-button1', GUI_BUTTON, '-showDelayOptions', ' '.join(GUI_DEFER_OPTIONS), '- '] error_values = ['2', '3', '239', '243', '250', '255'] # Instead of returning an error code to stderr, jamfHelper always returns 0 # and possibly returns an 'error value' to stdout. This makes it somewhat # spotty to check for some deferrment values including 0 for 'Start Now'. # The return value is an integer, so leading zeroes are dropped. Selecting # 'Start Now' should technically return '01'; instead, only '1' is returned # which matches the 'error value' for 'The Jamf Helper was unable to launch' # All we can do is make sure the subprocess doesn't raise an error, then # assume (yikes!) a return value of '1' equates to 'Start Now' try: proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() # Check that the return value does not represent an 'error value' if not out in error_values: # Special case for 'Start Now' which returns '1' if out == '1': return 0 else: return int(out[:-1]) else: return None except: # Catch possible CalledProcessError and OSError print "An error occurred when displaying the user prompt." return None count = 0 while True: count += 1 display_prompt() if str(count) in GUI_DEFER_OPTIONS: for x in range(1, loopTimes + 1): display_prompt()