Skip to content

Instantly share code, notes, and snippets.

@rmanly
rmanly / frogor_current_user.py
Last active January 26, 2016 18:37
use SystemConfiguration to get console user vs. stat'ing /dev/console etc.
# frogor user check v1
# http://osx.michaellynn.org/freenode-osx-server/freenode-osx-server_2013-04-09.html
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
from objc import NULL
import sys
username = (SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL) or [NULL])[0]
username = [username,''][username in [u"loginwindow", None]]
sys.stdout.write(username + "\n")
#!/bin/bash
# set counter to 0 and initialize ids array
i=0
ids=()
# ips=()
# read in the output from getConnectedUsers
# set variables for first and third items on a line
# to variable names key and value
#!/bin/bash
# looks like they changed they name again
# https://groups.google.com/forum/#!topic/munki-dev/w38roCmEgH0
# I have 11.2.1.203 and it is now just 'shoe'
# Copy the com.avid.bsd.shoe Helper Tool
PHT_SHOE="/Library/PrivilegedHelperTools/com.avid.bsd.shoe"
/bin/cp "/Applications/Pro Tools.app/Contents/Library/LaunchServices/com.avid.bsd.shoe" $PHT_SHOE
@rmanly
rmanly / sucatalog_size.py
Created October 17, 2014 00:30
sums up the values of the Size keys of Packages in Yosemite's sucatalog
#!/usr/bin/python
import plistlib
import urllib2
catalog_url = 'http://swscan.apple.com/content/catalogs/others/index-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog'
total_size = 0.0
yoyo_sucatalog = urllib2.urlopen(catalog_url).read()
yoyo_plist = plistlib.readPlistFromString(yoyo_sucatalog)
@rmanly
rmanly / enumerate_SMBHome.bash
Last active August 29, 2015 14:06
enumerate SMBHomes via content of mounted fileshare
shares=(foo{x..y})
for share in "${shares[@]}";do
printf '%s, %s\n' "USER" "SMBHome UNC" >> ~/Desktop/"${share}".csv
for dir in /Volumes/"${share}"/*; do
# Syntax highlighting gets this line wrong. Check out 'Parsing' here:
# http://wiki.bash-hackers.org/syntax/expansion/cmdsubst#a_closer_look_at_the_two_forms
printf '%s, %s\n' "${dir##*/}" "$(dscl /Search -read /Users/"${dir##*/}" SMBHome 2>/dev/null | awk '{print $2}')"
done >> ~/Desktop/${share}.csv
done
@rmanly
rmanly / notes.py
Last active August 29, 2015 14:05
get ComputerName via python
# Cocoa stuff is long enough already :(
from SystemConfiguration import *
# I asked about this in ##os-server on 2014-08-13
# Specifically whether it could be done without a
# subprocess.communicate() to scutil. After gneagle
# informed me that I should be looking in SystemConfiguration
# I remembered I had done that before for IP info and
# also about this post:
# http://kbyanc.blogspot.com/2010/10/python-enumerating-ip-addresses-on.html

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@rmanly
rmanly / cp_to_upper.bash
Created July 15, 2014 16:38
something gross I had to do because I forgot to .lower() something the first time around...
#!/bin/bash
for filename in ./*; do
short="${filename#*/}"
if [[ "${#short}" == 4 ]]; then
cp "$filename" "$(echo $filename | tr '[:lower:]' '[:upper:]')"
fi
done
@rmanly
rmanly / quit_prompt.bash
Last active August 29, 2015 14:02
small joke and illustrates using "proper" osascript method instead of heredoc
#!/bin/bash
check_running(){
open_apps=()
if pgrep -q "Microsoft Word"; then
open_apps+=("Microsoft Word")
fi
@rmanly
rmanly / Office Installer-14.4.2.plist
Last active December 15, 2016 07:32
Office for Mac pkginfo illustrating custom installs, notes, and installer_choices_xml keys
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>_metadata</key>
<dict>
<key>created_by</key>
<string>Ryan Manly</string>
<key>creation_date</key>
<date>2014-05-29T15:49:45Z</date>