Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
talkingmoose / queryOutlookFreeBusy.scpt
Last active April 5, 2024 22:09
AppleScript to look up an Exchange user's free/busy time using Outlook for Mac
tell application "Microsoft Outlook"
query freebusy exchange account 1 for attendees {"[email protected]"} range start time date "Thursday, September 8, 2016 at 12:00:00 AM" range end time date "Friday, September 9, 2016 at 12:00:00 AM" interval 60
end tell
@talkingmoose
talkingmoose / osascriptTextandButton.sh
Last active September 15, 2016 21:54
Method for returning both text and button from osascript dialog
#!/bin/sh
results=$( osascript -e "display dialog \"Text and Buttons!\" default answer \"Some text...\" buttons {\"Cancel\",\"OK\"} default button {\"OK\"}" )
theButton=$( echo "$results" | awk -F "button returned:|," '{print $2}' )
theText=$( echo "$results" | awk -F "text returned:" '{print $2}' )
exit 0
@talkingmoose
talkingmoose / ChangeOutlookUserSettings.sh
Created December 10, 2016 17:02
Shell script to change current user's Outlook settings
#!/bin/sh
# get current active console user
shortName=$( /usr/bin/logname )
# AppleScript command to set domain for console user in Outlook
command1="tell application \"Microsoft Outlook\" to set domain of Exchange account 1 to \"domainname\""
# AppleScript command to set user for console user in Outlook
command2="tell application \"Microsoft Outlook\" to set user name of Exchange account 1 to \"$shortName\""
@talkingmoose
talkingmoose / SendMail.sh
Created April 3, 2017 20:45
Send a message via authenticated mail SMTP server such as Hotmail or Google.
#!/bin/sh
# -v = verbose
# -r = From address
# -c = Cc, '[email protected],[email protected]'
# -b = Bcc, '[email protected],[email protected]'
# -s = Subject
# -S = variable key=value
echo "This is the message body and contains the message" | mailx -v -r [email protected] -c "[email protected]" -s "This is the subject" -S smtp="smtp-mail.outlook.com:587" -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user="[email protected]" -S smtp-auth-password="P@55w0rd" -S nss-config-dir=/etc/pki/nssdb/ -S HOME=/tmp -S ssl-verify=ignore [email protected]
@talkingmoose
talkingmoose / ToggleProxyOnOff.sh
Last active October 27, 2020 02:59
The script will disable any proxy server first. Then it will use ping to test connectivity to the proxy server for up to two minutes. If unable to reach the proxy server, it does nothing more. If the device gets a reponse from the ping, it will set the auto proxy URL and enable. Use this with a Jamf policy triggered by Network State Change and e…
#!/bin/sh
# enter the DNS or IP address of the network proxy
proxyAddress="proxy.domain.com"
# create a list of all Wi-Fi and Ethernet services
interfaces=$( networksetup -listallnetworkservices | egrep "Wi-Fi|Ethernet" )
# always turn of proxy configuration first for each network interface
while IFS= read anInterface
@talkingmoose
talkingmoose / kickstart commands.sh
Last active November 29, 2022 18:11
Commands from Apple's support page to enable all Remote Management options for a single user. https://support.apple.com/en-us/HT201710
#!/bin/sh
# start Remote Management
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate
# enable access for specified users
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -allowAccessFor -specifiedUsers
# specify users who can remotely access a machine and enable all privileges
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -users teacher,student -access -on -privs -All
@talkingmoose
talkingmoose / RenameComputerToSerialNumber.sh
Last active September 5, 2019 17:54
Renames Computer Name, Local Host Name and Host Name to serial number.
#!/bin/sh
# read serial number
serialNumber=$( /usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep "Serial Number" | /usr/bin/awk -F: '{ print $2 }' | /usr/bin/xargs )
# set the three computer names
/usr/sbin/scutil --set ComputerName "$serialNumber"
/usr/sbin/scutil --set HostName "$serialNumber"
/usr/sbin/scutil --set LocalHostName "$serialNumber"
@talkingmoose
talkingmoose / Reset JSS DEP Enrollment.sh
Last active April 27, 2017 19:45
Add to Self Service and enable only for specific users for testing and resetting DEP enrollments.
#!/bin/sh
sudo rm /var/db/.AppleSetupDone
sudo rm -rf /var/db/ConfigurationProfiles/
sudo rm /Library/Keychains/apsd.keychain
sudo jamf removeFramework
sudo reboot
exit 0
@talkingmoose
talkingmoose / jamfHelperProgress.sh
Last active March 16, 2021 18:33
Example for using JamfHelper to display progress during setup.
#!/bin/sh
/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper \
-windowType fs \
-title "This is the title" \
-heading "This is the heading" \
-description "Completing Step 1 of 4" \
-icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/com.apple.cinema-display.icns &
sleep 2
@talkingmoose
talkingmoose / Wait for SSID.sh
Last active March 11, 2022 20:30
Delay script to verify current Wi-Fi SSID is set before continuing.
#!/bin/bash
setupProcess=$( /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}' )
# specify SSID
while [[ "$setupProcess" != "TMI Wi-Fi" ]]
do
sleep 1
echo "Sleeping 1 second..."
setupProcess=$( /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}' )