GeekTool Battery Status Geeklet

Here’s a quick GeekTool geeklet for measuring the status of everything connected to your Mac that might have a battery. This geeklet will report on internal battery state such as battery status, battery health, and its cycle count. Also, if you have a Apple Magic Mouse and/or wireless keyboard, the battery status for those devices will be shown as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
#!/bin/sh
#
# Battery Stats Geeklet
# © 2013 Jason Howk (subaquatic.net) 
# Licensed under the MIT License.
#
 
BAT_CMD="ioreg -r -c AppleSmartBattery | grep -i capacity| tr -d ' '"
CUR_CAP=`eval ${BAT_CMD} |grep CurrentCapacity|awk -F "=" '{print $2}'`
MAX_CAP=`eval ${BAT_CMD} |grep MaxCapacity|awk -F "=" '{print $2}'`
DES_CAP=`eval ${BAT_CMD} |grep DesignCapacity|awk -F "=" '{print $2}'`
CYCLE_COUNT=`eval ${BAT_CMD} | grep CycleCount | tr -d "{}" | awk 'BEGIN {FS="="};{print $8}'`
 
MOUSE_BAT=`ioreg -c BNBMouseDevice | grep BatteryPercent | tail -1 | tr -d "|" | tr -d " " | awk -F '=' '{print $2}'`;
KEYBOARD_BAT=`ioreg -r -c AppleBluetoothHIDKeyboard | grep BatteryPercent | tail -1 | tr -d "|" | tr -d " " |awk -F '=' '{print $2}'`
 
printf "  System Battery: %0.2f%%\n" `echo "${CUR_CAP}/${MAX_CAP}*100" | bc -l`
printf "  Battery Health: %0.2f%% (CC:%s)\n" `echo "${MAX_CAP}/${DES_CAP}*100" | bc -l` ${CYCLE_COUNT}
if [ ${#MOUSE_BAT} -lt 1 ]; then
	echo "           Mouse: Disconnected"
else
	echo "   Mouse Battery: ${MOUSE_BAT}%"
fi
if [ ${#KEYBOARD_BAT} -lt 1 ]; then
	echo "        Keyboard: Disconnected"
else
	echo "Keyboard Battery: ${KEYBOARD_BAT}%"
fi

05. August 2013 by Jason
Categories: Mac, UNIX | Tags: | Leave a comment

GeekTool Geeklet for Measuring Airport

Here’s a quick GeekTool geeklet for measuring the certain Airport wireless network metrics. I work in a noisy environment with a ton of SSID’s and lots of noise, so it was important to be able to tell at a glance which AP I was associated with and the strength and noise associated with it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
#
# Airport Stats Geeklet
# © 2013 Jason Howk (subaquatic.net) 
# Licensed under the MIT License.
#
 
AIRPORT_CMD="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I"
 
if [ `${AIRPORT_CMD}|wc -l|tr -d ' '` -eq 1 ]; then
        echo "Airport Wireless OFF"
else         
	WIFI_AP=`${AIRPORT_CMD}|grep SSID| tail -1|awk -F ':' '{print $2}'|tr -d ' '`
        WIFI_RSSI=`${AIRPORT_CMD}|grep agrCtlRSSI |awk '{print $2}'`
        WIFI_NOISE=`${AIRPORT_CMD}|grep agrCtlNoise |awk '{print $2}'`
        WIFI_SN=`echo "(${WIFI_RSSI})-(${WIFI_NOISE})" | bc`
        echo "Airport Network SSID: ${WIFI_AP}"
        echo "                RSSI: ${WIFI_RSSI}dB"
        echo "               Noise: ${WIFI_NOISE}dB"
        echo "                 S/N: ${WIFI_SN}dB"
fi

05. August 2013 by Jason
Categories: Mac, UNIX | Tags: | Leave a comment

Xcode GCD Snippets

This is going to be short and sweet. For all those Mac/iOS developers that use Grand Central Dispatch, you’re probably tired of Xcode attempting to code complete dispatch_after once you’ve hit the dispatch_a while typing. 99.999999% of the time I’m after dispatch_async. It drives me crazy.

Interestingly enough Apple provided a dispatch_after code snippet, but not one for dispatch_async. A side effect of this oversight is that the code completion appears to show snippets first. So I’ve created two additional snippets that reflect the most common use cases that I encounter – dispatch_async with a global or main queue.

Download my Xcode GCD Snippets and install into ~/Library/Developer/Xcode/UserData/CodeSnippets and restart xcode.

Enjoy and never again see dispatch_after!

18. January 2013 by Jason
Categories: Objective-c | Tags: | Leave a comment

Getting server bit rate in AVFoundation

I was recently asked if it would be possible to provide the bit rate of the stream that is currently being viewed. Figuring that it would be possible as it has to be something that’s known to the AVPlayer, I agreed. Fortunately, I was correct. Unfortunately, it wasn’t as quick of an answer as I originally believed. Here’s how I solved it.

Continue Reading →

26. October 2012 by Jason
Categories: iOS, Objective-c | Tags: | Leave a comment

Provide a library that works with an iOS device and the simulator.

To create a combined library:

1.) Compile library for each SDK as usual.
2.) lipo -create libdevice.a libsimulator.a -output libcombined.a

That’s it.

25. August 2012 by Jason
Categories: Objective-c | Tags: | Leave a comment

Hide unwanted external drives on the Mac OSX desktop

I have a number of external hard drives attached to my Mac. Some for Time Machine, others for iTunes media, but they’re all external drives. In the MacOS finder preferences you have the ability to hide items from the desktop, and one of those is aptly labeled, “External disks.”

I like the desktop clutter free, and mounted volumes that I’ll never directly need access to (away from the command line), I don’t want to see on the desktop. However, I do want to see items like USB flash drives mounted on the desktop. Unfortunately these items are all considered “External disks.” However there is a solution.

And it’s a very simple solution. First, make sure that Finder is configured to display external disks on the desktop. The real answer lies in using the built in file flags that are part of Mac OSX. Simply issue a chflags hidden [file] and you’re already the majority of the way there.

Example:

$ chflags hidden /Volumes/Time\ Machine/
$ chflags hidden /Volumes/Media/

You can verify that the flags were set by using:

$ ls -ldO /Volumes/Media
drwxrwxr-x@ 11 jhowk  staff  hidden 442 Jul 29 18:29 /Volumes/Media

The last item that needs to be done is to restart the Finder. The chflags changes will not be reflected until the Finder has been restarted.

31. July 2012 by Jason
Categories: Mac | Tags: | 2 comments

Subversion recommits

A colleague at work was facing a dilemma and asked for help and I figured that the solution might be usable for others. Here’s the setup. Our SVN trunk typically matches production. Don’t ask why, it just does. Once a release is pushed into production the contents of whatever was deployed is merged into trunk. More like it obliterates what was in trunk.

In this particular case a commit was made after deployment but before the merge, effectively wiping out the changes to trunk. However we still needed to have the commits re-applied. We could have attempted some SVN slight-of-hand, but as it usually works out, the simplest solution is usually the best.

The easiest, and most scriptable solution was to use the way back machine and apply somediff and patch magic. Here’s what we did (make sure your completely up to date when you do).

  1. Get the files that were changed in the previous revision with
    svn log -v -r [REV] |grep "^ M " |awk '{print $2}' |cut -c2-
  2. Go old school and diff and patch
    svn diff -r [REV] [FILE] | patch -R [FILE]
  3. Commit away!

Assuming the changes you want applied are in version 2, and HEAD is at version 3, here’s how it might look

for f in `svn log -v -r 3 |grep "^   M " |awk '{print $2}'|cut -c2-`; 
do 
svn diff -r HEAD $f | patch -R $f; 
done

Lastly, issue the commit and your back to where you should be…

27. April 2012 by Jason
Categories: Development, UNIX | Tags: | Leave a comment

Get a quick fingerprint from public key

Due to the GitHub “SSH Key Vulnerability”, all of my keys were deactivated and I needed to reactivate them. Without going into details about the issue, GitHub provides you a list of your key fingerprints that you need to validate and reactivate. If you don’t know the fingerprints of your keys, you might think your stuck. Not necessarily.

If you have the public key handy, you can do this:

ssh-keygen -l -f [public key file]

And you get exactly what you need; a fingerprint of your public key.

13. March 2012 by Jason
Categories: Development, UNIX | Tags: , | Leave a comment

Xcode 4.3 quirks

With the Xcode 4.3 update, Xcode has become a full-fledged application in the App Store. There are a few implications to this seemingly innocuous change, but they can (and have) cause a few hiccups that I’m going to point out below. The obvious change is that Xcode is no longer installed via an installer. Should help out tremendously for updates so developers are no longer forced to re-download a gigabyte plus of data for the small fraction that was actually updated.

More importantly though, is that Xcode was just one application in a suite of tools that was installed in /Developer. In order for Xcode to become an “application” in the App Store vis-a-vis an installer, a number of changes were made that will affect Xcode users prior to 4.3.
Continue Reading →

26. February 2012 by Jason
Categories: Development, Mac, Objective-c | Tags: | Leave a comment

Getting a background texture behind a UITableView

In many apps when you viewing the top of a UITableView and you pull down you get one of three things: a plain white background (i.e. YouTube), a pull to refresh (i.e. twitter), or a textured or differently colored background (i.e. contacts). By default when you have a UITableView, you will get the first option, a plain white background.

If however you would like to do something like contacts where the perceived “background” of the table view is something other than default. If that’s the case, it’s relatively easy to do. Here’s how.

In your UITableViewController (usually viewDidLoad:)

// This sets the lighter linen looking background.  see UIColor for more "System Colors"
[[[self navigationController] view] setBackgroundColor:[UIColor underPageBackgroundColor]];
// Make the background of the table view transparent.
[[self tableView] setBackgroundColor:[UIColor clearColor]];

Then implement this method in your UITableViewController:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor whiteColor]];
}

After playing around and failing in different ways, this seems to be the simplest solution by far. Simple, easy and does what it should.

05. December 2011 by Jason
Categories: Development, Mac, Objective-c | Leave a comment

← Older posts