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