Posted on 07-20-2021 06:38 AM
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
Posted on 07-20-2021 12:34 PM
In the policy what did you set for the trigger and in the execution frequency?
Posted on 07-21-2021 02:34 AM
Login and Recurring Check-in, ongoing
Posted on 07-21-2021 06:46 AM
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?