A screensaver to send your display to sleep.

I poked around a bit looking for something that did this, and couldn’t find anything, apart from some sample code using a private API to send the display to sleep, so I whacked that into a screeensaver.

https://sites.google.com/a/explanatorygap.net/misc-sw/files/SleepSaver.saver.zip

This does use a private API and thus could do anything. No warranties, may destroy your machine, etc etc etc, but works for me.

code:

//
//  SleepSaverView.m
//  SleepSaver
//
//  Created by Nigel Kersten on 1/29/09.
//  Copyright (c) 2009, Google Inc. All rights reserved.
//

#import "SleepSaverView.h"

@implementation SleepSaverView

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
if (! isPreview) {
[self dimDisplayNow];
}
}
return self;
}

- (BOOL)hasConfigureSheet
{
return NO;
}

- (NSWindow*)configureSheet
{
return nil;
}

- (void) dimDisplayNow {
io_registry_entry_t r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
if (r) {
IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanTrue);
IOObjectRelease(r);
}
}

@end

Awesome Daemons and Agents TechNote

http://developer.apple.com/technotes/tn2005/tn2083.html

This is really just going here so I can find it again as I can never remember what keywords to search with to find it and I often need to refer to it.

AAAAA+++ Excellent TechNote Would Read Again kthxbye

Macworld 2009: Puppet on Mac OS X

Macworld 2009: Python for System Administration

Presentation here:

The future of iPhone management? :)

Not completely working, but…

dre on the LKDC

So dre has done a great overview of the LKDC in Leopard, including a more detailed wiki page. There really isn’t enough info out there about the LKDC, and it’s quite awesome technology.

useful screen bash function

So I pretty much live in screen permanently these days, and there are a gazillion awesome introductions out there to screen that describe the amazing advantages of screen.

One thing that has been a minor niggle has been the clunky way you pick which screen session you wish to reattach to if you have multiple sessions active, so I whipped up this bash function that I’ve been finding really useful.

function scr() {

  if [ ! $1 ]; then

    screen -D -R

  else

    i=1

    for j in $(screen -list | awk --posix '/^[[:space:]]*[[:digit:]]{2,}.*$/{print $1}'); do

      screens[${i}]=$j

      let i=i+1

    done

    # test if integer

    if ! [ $1 -eq $1 2> /dev/null ]; then

      echo "You must supply an integer as the argument"

    elif [ $1 -eq 0 ]; then

      echo "screens list count starts at 1, not zero."

    elif [[ ${1} -gt ${#screens[@]} ]]; then

      echo "only ${#screens[@]} screens exist"

      screen -list

    else

      screen -D -R ${screens[$1]}

    fi

  fi

}

So you can basically go scr to reattach to a single screen session, scr 1 to reattach to the first, scr 2 to reattach to the second, etc etc.

I’m kind of expecting someone to pipe up now and point out a much easier way… :)

Querying hosts with DirectoryService

So as host, ping, nslookup, dig etc don’t use the same resolver path as the rest of the OS, we used to always use lookupd for this.

It’s not exactly the most obvious solution in the world, but since lookupd, netinfod and memberd were all rolled into DirectoryService in 10.5, we now use dscacheutil to do this.


$ dscacheutil -q host -a name www.google.com
name: www.l.google.com
alias: www.google.com
ip_address: 74.125.19.104
ip_address: 74.125.19.147
ip_address: 74.125.19.99
ip_address: 74.125.19.103

This is a much more appropriate way of debugging host problems if the *nix tools aren’t showing any problems but OS X components are.

This will fetch the result from the cache, and if it’s not there, fetch it and place it in the cache. If you want to make sure this is a fresh request, do:

dscacheutil -flushcache

and you can always do this:

dscacheutil -cachedump -entries host

to inspect the cache for hosts.

I was actually debugging a Mobile Account problem the other day where the user agreed to create a mobile account at the loginwindow, and yet it kept logging them in with the network account.

Inspecting the DirectoryService cache with:

dscacheutil -cachedump -entries user

showed that the /Local/Default entry for that user was never retrieved. Flushing the cache fixed it.

Turns out the user said no to creating a Mobile Account once, and then logged out without rebooting (and didn’t tell us they’d said no ;-) ). OS X kept the cached entry around and failed to update when creating the Mobile Account as it should have.

Need to get that one into radar….

MacPort issue when using patch…

After spending a little while banging my head against the wall over this one….

root@snicko [ ~ ]
# port install git-core +svn +bash_completion
---> Applying patches to perl5.8
Error: Target org.macports.patch returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_perl5.8/work/perl-5.8.8" && patch -p0 < '/opt/local/var/macports/sources/rsync.macports.org/release/ports/lang/perl5.8/files/patch-makedepend.SH'" returned error 2
Command output: Get file makedepend.SH from Perforce with lock? [y]
Perforce client error:
Connect to server failed; check $P4PORT.
TCP connect to perforce failed.
perforce: host unknown.
patch: **** Can't get file makedepend.SH from Perforce

Error: The following dependencies failed to build: p5-error perl5.8 p5-libwww-perl p5-compress-zlib p5-compress-raw-zlib p5-io-compress-base p5-scalar-list-utils p5-io-compress-zlib p5-html-parser p5-html-tagset p5-uri p5-svn-simple subversion-perlbindings apr apr-util db44 sqlite3 gawk gmake readline neon subversion bash-completion p5-term-readkey rsync popt
Error: Status 1 encountered during processing.

I finally found Jack Palevich's post talking about exporting the POSIXLY_CORRECT environment variable as follows.


POSIXLY_CORRECT=1 port install git-core +svn +bash_completion

Of course now I’ve run into an issue with tcl…. *sigh*, but I’ve seen the patch issue above crop up a few times, and this certainly seems to be fixing it.

It’s bad enough that MacPorts and Fink can’t depend upon Apple to provide sane libraries and headers in OS X, and thus you end up with most of another whole freaking operating system in /opt/local or /sw, but I simply refuse to have both installed, no matter how frustrating it is that I can’t get all the software I need working via just one of them.

More MCX in DSLocal from Greg…

And along similar lines to the afp548.com article on this, Greg Neagle written a similar piece describing how he’d use it in his environment (and it even has screenshots …).