Skip to main content
Question

Script runs locally, but only once sometimes as policy


Forum|alt.badge.img+4

I have the script below which runs fine locally but when used as a reoccurring policy only runs once, sometimes or not at all. Any ideas welcome....?

 

#!/usr/bin/env zsh currentUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\\n");') echo $currentUser function default_browser () { sudo -u $currentUser osascript <<-AS use framework "AppKit" use AppleScript version "2.4" use scripting additions property NSWorkspace : a reference to current application's NSWorkspace property NSURL : a reference to current application's NSURL set wurl to NSURL's URLWithString:"https://www.apple.com" set thisBrowser to (NSWorkspace's sharedWorkspace)'s ¬ URLForApplicationToOpenURL:wurl set appname to (thisBrowser's absoluteString)'s lastPathComponent()'s ¬ stringByDeletingPathExtension() as text return appname as text AS return } currentBrowser=$(sudo -u $currentUser printf '%s\\n' $(default_browser)) forcedBrowser="Microsoft%20Edge" echo $currentBrowser if [ "$currentBrowser" = "$forcedBrowser" ]; then echo "Yay" exit 0 else if [ -f "/usr/local/ArtsEd/defweb.py" ]; then sudo -u $currentUser /usr/bin/python /usr/local/ArtsEd/defweb.py else /bin/mkdir -p /usr/local/ArtsEd /usr/bin/curl https://artsed001.blob.core.windows.net/macos-config/defweb.py --output /usr/local/ArtsEd/defweb.py sudo -u $currentUser /usr/bin/python /usr/local/ArtsEd/defweb.py fi fi exit 0

3 replies

junjishimazaki
Forum|alt.badge.img+10

In the policy what did you set for the trigger and in the execution frequency?


Forum|alt.badge.img+4

Login and Recurring Check-in, ongoing


junjishimazaki
Forum|alt.badge.img+10

Have you looked in the policy log to see what the status shows? If the policy on the mac shows pending, have you checked if there are any failed commands on that mac?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings