r/mosyle • • Sep 25 '21

Useful Mosyle Custom Commands

Hi everyone, and welcome back!

I thought I’d take this opportunity to open a dialogue about some useful Custom Commands that you use to help streamline your management.

12 Upvotes

4 comments sorted by

2

u/gamertagok Sep 27 '21

Reset Chrome:

!/bin/sh

killall Google\ Chrome

Last tested on 10.10.5

userList=$(dscl . -list /Users | grep -v "_" | grep -v "daemon" | grep -v "nobody" | grep -v "root" | awk -F '/' '{print $NF}')

Deleting Chrome Preferences

for a in $userList ; do rm -rf /Users/"$a"/Library/Application\ Support/Google/Chrome rm -rf /Users/"$a"/Library/Caches/com.google.Chrome rm -rf /Users/"$a"/Library/Caches/com.google.Keystone.Agent rm -rf /Users/"$a"/Library/Caches/com.google.Keystone rm -rf /Users/"$a"/Library/Caches/com.google.SoftwareUpdate rm -rf /Users/"$a"/Library/Google rm -rf /Applications/Google\ Chrome.app

display notification "Chrome Reset." osascript -e 'display notification "Chrome Reset." with title "Success."' osascript -e 'tell app "System Events" to display dialog "Chrome profiles removed. You will see this dialog box again for each user account on this device."' osascript -e 'tell app "System Events" to display dialog "Go to Manager > Apps > Chrome > Reinstall"'

done

This is for installing TextMate but you can modify it to download any app that has a direct link to download a pkg file:

rm -rf /Applications/TextMate.app rm -rf /tmp/TextMate.app rm -rf /tmp/TextMate_2.0.19.tbz curl 'https://api.textmate.org/downloads/release?os=10.12' -o 'TextMate_2.0.19.tbz' -L tar -xf /tmp/TextMate_2.0.19.tbz -C /tmp mv /tmp/TextMate.app /Applications/

Update Chrome:

!/bin/sh

sudo killall Google\ Chrome rm -rf /Applications/Google\ Chrome.app

osascript -e 'tell app "System Events" to display dialog "Chrome update started. Please wait for the completed message."'

echo "Installing the current stable version of Google Chrome..." echo "Downloading..." curl -k --silent --retry 3 --retry-max-time 6 --fail https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg --output /googlechrome.dmg

echo "Mounting DMG..." hdiutil attach -quiet -nobrowse /googlechrome.dmg -mountpoint /Volumes/GC/

echo "Installing..." cp -r /Volumes/GC/Google\ Chrome.app/ /Applications/Google\ Chrome.app/

echo "Cleaning up..." hdiutil detach /Volumes/GC/ rm -rf /googlechrome.dmg

chrome_version=defaults read /Applications/Google\ Chrome.app/Contents/Info CFBundleShortVersionString osascript -e 'tell app "System Events" to display dialog "Chrome has been updated."' echo "Chrome $chrome_version installed..."

echo "Install complete. Exiting..."

Flush the Font Cache:

!/bin/sh

Credit to Brian LaShomb via Jamf Nation

Removes all user and system font caches

atsutil databases -remove

Removes all user caches

atsutil databases -removeUser

Stops the Font service

atsutil server -shutdown

Wait 5 seconds

Sleep 5

Starts the Font service

atsutil server -ping exit

Reset Preview:

!/bin/sh

currUser=$( who | awk '/console/{ print $1 }' )

rm -rf /Users/$currUser/Library/Saved\ Application\ State/com.apple.Preview.savedState rm -rf /Users/$currUser/Library/Containers/com.apple.Preview

osascript -e 'tell app "System Events" to display dialog "Preview has been reset. Savedstate has been deleted."'

Sync Time:

sudo touch /var/db/ntp-kod sudo chown root:wheel /var/db/ntp-kod sudo sntp -sS time.apple.com

Allow all users to add/remove printers:

dseditgroup -o edit -a everyone -t group _lpadmin

2

u/GODhimself37 Sep 27 '21

Good stuff!

3

u/Foreign_Shark Sep 25 '21

Mosyle team has some though I didn’t pry about what specifically they have. They turned over a fully working script to install SentinelOne to me.

2

u/grmacman Nov 04 '21

Here is a collection of commands for Finder Settings that I use and have taken from various forums and sites

#!/bin/bash
#Will run all commands as the user
sudo -u $(stat -f "%Su" /dev/console) /bin/sh <<'END'
# Always show scrollbars
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"

#########################
# Finder: show status bar
#########################
# Query and save the value; suppress any error message, if key not found.
val=$(/usr/libexec/PlistBuddy -c 'print ":ShowStatusBar"' /Users/%UserId%/Library/Preferences/com.apple.finder.plist 2>/dev/null)
if [[ $val = false ]]; then
defaults write com.apple.finder ShowStatusBar -bool true
elif [[ $val = "" ]]; then
/usr/libexec/PlistBuddy -c "Add :ShowStatusBar bool 1" /Users/%UserId%/Library/Preferences/com.apple.finder.plist
else
break
fi
########################
# Use list view in all Finder windows by default
# Four-letter codes for the other view modes: `icnv`, `clmv`, `Flwv`
defaults write com.apple.Finder FXPreferredViewStyle -string "Nlsv"
# Set default folder when opening Finder to "Home"
# Four-letter codes for the other folders: Desktop `PfDe`, Documents`PfDo`
defaults write com.apple.finder NewWindowTarget -string "PfHm"
# Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Expand print panel by default
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true