Skip to content

Instantly share code, notes, and snippets.

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

geoff geoffrepoli

🏄‍♂️
View GitHub Profile
#!/usr/bin/env bash
user=$(/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");')
pass=$(osascript -e 'display dialog "Enter password:" default answer "" giving up after 60 with text buttons {"Authenticate"} default button 1 with hidden answer' -e 'return text returned of result')
attempts=1
until dscl . authonly "$user" "$pass" &>/dev/null ; do
# lines 9 and 10 are only necessary if you wish to display no. of attempts remaining before failure
attemptsRemaining=$(( 4 - attempts ))
[[ $attemptsRemaining -eq 1 ]] && s= || s=s
## REMOVE FIRST CHARACTER FROM STRING
sed '/^.//'
== Example ==
$ echo "foo" | sed 's/^.//'
oo
____________________________________________________________________
@geoffrepoli
geoffrepoli / Reset Printing System
Last active June 23, 2017 23:28
command-line dupe of System Preferences "Reset printing system" advanced option. As with that option, this does not remove drivers.
#!/usr/bin/env bash
# stop print services
launchctl stop org.cups.cupsd
# back up existing configs
mv /Library/Printers/InstalledPrinters.plist /Library/Printers/InstalledPrinters.plist.bak
mv /etc/cups/cupsd.conf /etc/cups/cupsd.conf.bak
mv /etc/cups/printers.conf /etc/cups/printers.conf.bak
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
@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:")
#!/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 / 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)"' \;
yourcommand && history -d $((HISTCMD-1))
@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 &&
@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