Skip to content

Instantly share code, notes, and snippets.

View geoffrepoli's full-sized avatar
🏄‍♂️

geoff geoffrepoli

🏄‍♂️
View GitHub Profile
@geoffrepoli
geoffrepoli / sync_client_hostname.sh
Last active October 6, 2016 18:52
Changes HostName and LocalHostName to match ComputerName while accounting for non-ASCII characters
#!/bin/bash
comp_name=$(scutil --get ComputerName)
if [[ "$comp_name" = *[![:ascii:]]* ]]; then
echo "Error: Computer name contains non-ASCII characters. Please modify with the command \`scutil --set ComputerName <value>\` before running this script"
exit 1
else
host_name=$(echo "$comp_name" | sed -e "s/'//g;s/ /-/g;s/\///g" | awk '{print tolower($0)}')
echo "Changing hostname and Bonjour name to $host_name ..."
scutil --set LocalHostName "$host_name"
scutil --set HostName "$host_name"
@geoffrepoli
geoffrepoli / list-all-third-party-launch-services.sh
Last active October 26, 2021 23:45
creates formatted logfile of all third-party launch agents, daemons, kernel extensions, login items, and library extensions. user must be admin to run, you will be prompted for a password
sh -c 'echo "===> Launch Daemons <==="; sudo launchctl list | sed 1d | awk '"'"'!/0x|com.apple/{print $3}'"'"' | grep -Ev '"'"'(cups|ntp|ssh|cron)'"'"'; \
echo "\n===> Launch Agents <==="; launchctl list | sed 1d | awk '"'"'!/0x|com.apple/{print $3}'"'"'; \
echo "\n===> Kernel Extensions <==="; kextstat -kl | awk '"'"'!/com.apple/{print $6}'"'"'; \
[ -f $HOME/Li*/Preferences/com.apple.loginitems.plist ] && { echo "\n===> Login Items <==="; /usr/libexec/PlistBuddy -c "Print :SessionItems:CustomListItems" $HOME/Library/Preferences/com.apple.loginitems.plist | awk -F'"'"'= '"'"' '"'"'/Name/{print $NF}'"'"'; }; \
echo "\n===> Privileged Helper Tools <==="; ls -1A /Li*/PrivilegedHelperTools; \
echo "\n===> PreferencePanes <==="; ls -1A /Li*/PreferencePanes; \
echo "\n===> Internet Plug-Ins <==="; ls -1A /Li*/Internet\ Plug-Ins | grep -v Disabled; \
echo "\n===> Total Loaded Fonts <==="; echo $(( $(wc -l <<< "$(ls -1A /Li*/Fonts)" | tr -d '"'"' '"'"') + $(wc -l <<< "$(ls -1A $HOME/Li*/Fonts)" | tr -d
@geoffrepoli
geoffrepoli / progress-bar-function.sh
Last active December 13, 2022 15:12
function you can place in your scripts and call on any command where you want progress animations. replaced the earlier snippet that was less plug and play. the characters in $loop can be replaced with other characters - printf prints 3 individual random characters from the string stored in $loop
_progressBar() {
local pid="$1"
if ps -p "$pid" &>/dev/null; then
loop='▁▃▄▅▆▇█'
while kill -0 "$pid" &>/dev/null; do
printf "%b\r" "${loop:$((RANDOM%${#loop})):1}${loop:$((RANDOM%${#loop})):1}${loop:$((RANDOM%${#loop})):1}"
sleep 0.1
done
fi
}
@geoffrepoli
geoffrepoli / applescript-parallel-processes
Created November 2, 2016 15:35
Run parallel processes in AppleScript
set subShell1 to "(your_command1)"
set subShell2 to "(your_command2)"
set yourScript to subShell1 & " & " & subShell2
do shell script yourScript
@geoffrepoli
geoffrepoli / ground-control-launchpad-silent-install.bat
Last active March 21, 2017 14:03
silent gclp + no itunes install bat. sets launchpad name to the computer name
@echo off
setlocal enableextensions
for /F "usebackq" %%x in (`hostname`) do (
set COMPUTERNAME=%%x
)
msiexec /i <Path>\AppleApplicationSupport.msi /q /norestart &&
msiexec /i <Path>\AppleApplicationSupport64.msi /q /norestart &&
msiexec /i <Path>\AppleMobileDeviceSupport6464.msi /q /norestart &&
yourcommand && history -d $((HISTCMD-1))
@geoffrepoli
geoffrepoli / List all third-party software and their version numbers
Last active November 16, 2022 16:03
lists all non-Apple applications names and versions, separated by "-" delimiter
find /Applications -name *.app -maxdepth 2 -exec \
bash -c '[[ ! $(defaults read "{}"/Contents/Info.plist CFBundleIdentifier) =~ "com.apple" ]] \
&& echo "$(basename "{}" | sed 's/.app.*//')-$(defaults read "{}"/Contents/Info.plist CFBundleShortVersionString)"' \;
#!/bin/bash
# geoff repoli
# customize this variable with relatively unique + identifiable string that matches the process(es)
# you want to terminate. not case-sensitive. for example:
# for all microsoft applications + background services: application="microsoft"
# for microsoft outlook: application="outlook" OR application="microsoft outlook"
application="your string goes here"
# get pids of any running microsoft processes
@geoffrepoli
geoffrepoli / pass-user-input-into-shell-script.sh
Last active February 22, 2018 19:37
applescript window dialog
getUserInput()
{
launchctl asuser $(stat -f %u /dev/console) osascript <<-APPLESCRIPT
tell app "System Events"
text returned of (display dialog "$1" default answer "" buttons {"OK"} default button 1)
end tell
APPLESCRIPT
}
var=$(getUserInput "type string:")
parse_array() {
FS=':'
key=(); val=()
for (( i=0 ; i < $(eval echo \${#$1[@]}) ; i++ )); do
key+=( "$(eval echo \${$1[$i]} | awk -F${FS} '{print $1}')" )
val+=( "$(eval echo \${$1[$i]} | awk -F${FS} '{print $2}')" )
done
}
# Assuming script contains myarray=( "key1:value1" "key2:value2" )
parse_array myarray