Skip to content

Instantly share code, notes, and snippets.

View pmbuko's full-sized avatar
💁‍♂️
working hard(ly)

Peter Bukowinski pmbuko

💁‍♂️
working hard(ly)
  • Cupertino, CA
View GitHub Profile
@pmbuko
pmbuko / path_to_ad_home.applescript
Created October 18, 2013 16:53
Part of an Automator service that returns the Active Directory home path for a selected user. (http://yourmacguy.wordpress.com/2013/08/12/path-to-ad-homedir-service/)
on run {userName}
set DOMAIN to (do shell script "/usr/bin/dscl localhost -list /Active\\ Directory")
set PROTOCOL to "smb" -- or "afp"
set mac_home to (do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/" & DOMAIN & "/All\\ Domains/Users/" & userName & " SMBHome | awk '{gsub(/\\\\/,\"/\"); print \"" & PROTOCOL & ":\" $2}'")
set win_home to (do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/" & DOMAIN & "/All\\ Domains/Users/" & userName & " SMBHome | awk '{print $2}'")
if mac_home is "" then
display dialog "Could not find username: " & userName buttons "OK" default button "OK" with icon 0
else
set theDialog to display dialog "Mac: " & mac_home & "
Windows: " & win_home buttons {"Copy Mac", "Copy Windows", "OK"} default button "Copy Mac"
@pmbuko
pmbuko / syspref_handler.applescript
Created October 18, 2013 16:59
An applescript url handler that opens System Preference panes passed to it. (http://yourmacguy.wordpress.com/2013/07/17/make-your-own-url-handler/)
on open location this_URL
-- passed urls should be "syspref://[PaneName]
-- or "syspref://[Pane_Name]" -- no spaces
set x to the offset of ":" in this_URL
set sp to text from (x + 3) to -1 of this_URL
set pane to do shell script "echo \"" & sp & "\" | awk '{gsub(\"_\",\"\\\\ \"); print}'"
set h to path to home folder
set home to POSIX path of h
set path_heads to {"/System/", "/", home}
set pref_pane to text from (x + 3) to -1 of this_URL
@pmbuko
pmbuko / auth_find.sh
Created October 18, 2013 17:05
A shell script that recursively finds and replaces usernames inside files within a directory.
#!/bin/bash
workpath=/opt/auth_files/
outfile=/root/auth_find-$1
# friendly usage funtion, called if no argument is supplied
usage ()
{
cat<<EOF
Usage: auth_find [username] [new-username]
@pmbuko
pmbuko / pdf2ps_print.sh
Last active December 25, 2015 21:48
Prints a pdf as postscript to an lpr queue. Requires pdf2ps. (http://yourmacguy.wordpress.com/2009/08/18/print-pdfs-as-postscript-to-an-lpr-queue/)
#!/bin/bash
# grab first argument as pdf filename and generate ps filename
thePDF=$1
thePS=$(echo $thePDF.ps)
queueName=$2
usage() {
cat<<EOF
Usage: psprint [your pdf] [lpr queue]*"
#!/usr/bin/perl -w
use strict;
# This script automates the process of adding usersets to the user_lists section
# of the SGE cluster queue configs. It takes the userset name as a command line
# argument or it prompts for the userset name if no argument is given. Multiple
# lists can be submitted as a comma-separated list *without spaces*.
# queues to be modified
my @queues = qw(
@pmbuko
pmbuko / shotshadows.sh
Created October 18, 2013 17:32
Turns on/off window shadows in OS X screenshots. (http://yourmacguy.wordpress.com/2008/07/29/screenshot-shadows/)
#!/bin/bash
usage () {
/bin/echo "Usage: shotshadows [off|on]"
exit 1
}
if [ $# == 1 ]; then
if [ $1 == "off" ]; then
/bin/echo "Disabling drop shadows in screenshots and restarting SystemUIServer"
@pmbuko
pmbuko / change_password.scpt
Last active December 29, 2015 03:49
This is how ADPassMon opens the Change Password dialog box in OS X.
--this first line gets the x in os version 10.x
set osVersion to (do shell script "sw_vers -productVersion | awk -F. '{print $2}'") as integer
tell application "System Preferences"
try -- this won't work if UI scripting is not enabled
set current pane to pane id "com.apple.preferences.users"
activate
tell application "System Events"
tell application process "System Preferences"
if osVersion is less than or equal to 6 then
click radio button "Password" of tab group 1 of window "Accounts"
@pmbuko
pmbuko / python_line_matcher.py
Last active August 29, 2015 13:58
This is a python example for an easy way to search file lines for lines matching a specific regex. You need to pass the filename to search as the first argument.
#!/usr/bin/env python
import sys, re
# get first command line argument as filename
input_file = sys.argv[1]
# suck in file contents
with open(input_file) as f:
content = f.readlines()
@pmbuko
pmbuko / finder-file-handler.applescript
Last active August 3, 2018 07:56
Use this code in an Applescript to create a file handler that will allow you to click on urls of the form "finder://~/Dropbox/Project/Documents" to open that location in the Finder.
on open location this_URL
-- passed paths should be "finder://[/path/to/directory]
-- spaces in path names should be replaced with a url-friendly '%20'
set x to the offset of ":" in this_URL
set passed_path to text from (x + 3) to -1 of this_URL
set my_path to do shell script "echo \"" & passed_path & "\" | awk '{gsub(\"%20\",\"\\\\ \"); print}'"
do shell script "open " & my_path
end open location
display dialog "Please enter the account to give administrator privileges." default answer ""
set username to text returned of result
try
do shell script "/usr/sbin/dseditgroup -o edit -a 'DOMAIN\\" & username & "' -t user admin" with administrator privileges
set question to display dialog "Successfully granted administrator privileges to " & username & "." buttons {"Quit"} default button 1
set answer to button returned of question
if answer is equal to "Quit" then
return
end if
on error