www.wallcity.org | Zack Smith

TIme Machine Drawning

Here is my time machine drawing for Charles new ebook. I don’t get to draw often anymore, but It was kind of neat seeing how much illustrator has grown up since I last used it for this kind of thing. The orginal design was found on the internet by charles and can be found here, and my version can be found here Read more »

Simple Little Warranty Parser


if anyone is interested I have a python prototype of @glarriza’s warranty ruby script that spits all keys out as a dict http://gist.github.com/1357622

I would have used his but I am writing something in python that needed this directly and I did not want to call an external command.

-Z

system-type a new little command line

I just made a little command line grab it here:

https://github.com/acidprime/system-type

This little binary will tell you if you have a Laptop or Desktop.
It reads this value using the system-type in IOKit (IOPlatformExpertDevice).
You can parse this value your self using the ioreg (-l) command but Its not
formatted well, so I decided to make this as its a pretty common request.
For instance I once had a school district that wanted to turn off wireless
on all Desktops as they were having MYNAME(37) bonjour name conflict issues.

There is a little example.command shell script to show you the two ways you
would use this in your scripts. laptops are value 2 (exit 1) and Desktops are
value 1 (exit 0). The exit values allow you to use standard logic built-in to
run the command and use its exit value. Or if you think thats lame you can
parse the text. To each there own but I like exit values

Known Issues:
As I recall this does not cover PowerPC machines, but I have not seen an intel
that does not use this value. Maybe iPad 3 will be 3 ;)

To Do:
I will make a little installer for it as some point and put it in
/usr/local/bin/system-type
Could use some options as well such as controlling behaviour
Maybe XML output, and put some other values?

Replacement for:

#!/bin/bash
declare -x awk="/usr/bin/awk"
declare -x ioreg="/usr/sbin/ioreg"
# Intel and future systems test
declare IOREG="$("$ioreg" -l |
	"$awk" 'BEGIN {FS="[<>]"}
	/.*\"system-type\".=./{
	systype=$2
	if ( systype == 1 )
		{ print "D" ; exit 0 }
	# System type 1 is a Desktop
	else if ( systype == 2 )
		{ print "L" ; exit 0 }
	# System type 2 is a Laptop
	}')"

Sample NSStatusItem Application

ScriptMenu

Here is the sample NSStatusItem Application
mentioned in my slides at Mac Tech Conf 2011 can be found here:

https://github.com/acidprime/StatusItem/downloads

Fun with Textmate URI links

So I have been doing allot of custom cocoa URL code over the last week, so I thought I would go look around for applications that have custom URL types. In my search I found the following url type for TextMate (txtmt). Here is an example that will open up text mates own info.plist and show you were these are declared.

txmt://open?url=file:///Applications/TextMate.app/Contents/Resources/Info.plist&line=&column=36
Here is an example of this link
There is a quick blog post about it here on their site. All in all I can see some pretty cool ideas for this, such as what I am big fan of which is interactive documentation. I am a big URL nerd and to mention one other cool one I knew about previously is transmit’s transmitreg:// which they use for serial numbers ,an awesome way to fill in serials that every vendor should do.

Converting a Check Box value to Boolean

Here is simple little objective c method that will take a IBOutlet and query its value to return a boolean. I typically need to do this to run a logical test on the interface value. My guess is properties & bindings are the better way to do this but as BOOL is not an object I am not quite sure how that would be done.

-(BOOL)evaluateCheckBox:(NSButton *)evalButton
{
	// Gather data from interface
	if ( [evalButton state] == NSOnState ){
		return YES;
	}
	if ( [evalButton state] == NSOffState ){
		return NO;
	}
}

European Macintosh System Administrators Meeting 2011

Well its official , I will be speaking at the European Macintosh System Administrators Meeting 2011 in Göteborg, Sweden. Check out the details here.

Pull the Script Name in BASH

I very often use the Script Name as the log file name, it allows me to make the logs
always match up to the script even though the code is the same in all scripts
here is a quick example on how to do that

#!/bin/bash
declare -x SCRIPT_PATH="$0"
declare -x SCRIPT_NAME="${0##*/}"

echo $SCRIPT_PATH

echo $SCRIPT_NAME

A more raw example (Same Output):

#!/bin/bash
echo $0
echo ${0##*/}

Output:

/Users/acid/Dropbox/code/bash/scriptname.sh
scriptname.sh

Simple Folder Loop with Exclusions

Here is a little loop that can exclude folders, I started it for some find
code that would exclude "system" files during a permissions change.
#!/bin/bash
OLDIFS="$IFS"
IFS=$'\n'
for FOLDER in /* ; do
 [ -L "$FOLDER" ] && continue
 if [ -d "$FOLDER" ] ; then
 if  [ "$FOLDER" != '/Volumes' ] &&
 [ "$FOLDER" != '/System' ] &&
 [ "$FOLDER" != '/Network' ] &&
 [ "$FOLDER" != '/Recycled' ] &&
 [ "$FOLDER" != '/cores' ] &&
 [ "$FOLDER" != '/dev' ] &&
 [ "$FOLDER" != '/net' ]
 then
 echo "$FOLDER"
 fi
 fi
done
IFS="$OLDIFS"

Simple BASH Console User Check

I have seen this in done pretty much the same way in all languages, so my continued effort to give away all my bash scripts so I never have to use it again, here is a quick little example of who to check for console users with bash,who and awk.

#!/bin/bash
declare -x who="${who:="/usr/bin/who"}"
declare -x awk="${awk:="/usr/bin/awk"}"
declare -xi CONSOLE_USERS="$($who |
		$awk '/.*console/{++n}END{print n}')"
declare -x CONSOLE_USER="$($who |
		$awk '/console/{print $1;exit}' )"
if [ $CONSOLE_USERS -eq 0 ] ; then
	echo "No console users present"
else
	echo "$CONSOLE_USER is logged in"
fi