Tag Archives: Apple

Hibernating in OSX Lion

In OSX Lion (might also be the case for older versions to), there is no direct way to hibernate a laptop except running out of battery power. The only available option is sleep, which will wake from memory; so it keeps draining the battery. It is possible to change this default behavior with the utility pmset. From the man page:

     We do not recommend modifying hibernation settings. Any changes you make are not supported. If you choose to do so anyway, we recommend
     using one of these three settings. For your sake and mine, please don't use anything other 0, 3, or 25.

     hibernatemode = 0 (binary 0000) by default on supported desktops. The system will not back memory up to persistent storage. The system must
     wake from the contents of memory; the system will lose context on power loss. This is, historically, plain old sleep.

     hibernatemode = 3 (binary 0011) by default on supported portables. The system will store a copy of memory to persistent storage (the disk),
     and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from disk image.

     hibernatemode = 25 (binary 0001 1001) is only settable via pmset. The system will store a copy of memory to persistent storage (the disk),
     and will remove power to memory. The system will restore from disk image. If you want "hibernation" - slower sleeps, slower wakes, and bet-
     ter battery life, you should use this setting.

So by default, the system uses hibernatemode=3. All we need to do it change it to 25 and the sleep function will hibernate the computer:

sudo pmset hibernatemode 25

Don’t forget to change it back to 3 to get the default behavior back.

Restore sparsebundle extended attributes after rsync

If you rsync a sparse bundle to another Mac without the -E flag (or if you copy it to a non Mac system), you will loose the ability to double click on it in the Finder to mount it. This is because the extended attributes telling the Finder the folder is actually a bundle are lost in the transfer.

The following piece of code I found here fixed the problem for me. Simply compile and run the code giving the path to the bundle in parameter and it will restore the attributes.

/*
 setxattrs - bubbaATbubba.org
 
 Properly sets sparse bundle extended attributes lost when rsyncing
 sparse bundle data to a platform that does not support extended
 attributes.  This is only need when restoring/retrieving the
 bundle.
 
 To use, sync/copy all bundle files, then run this tool on the
 sparse bundle:
 % gcc -o setxattrs setxattrs.c
 % ./setxattrs mybackup.sparsebundle
 % xattr -l mybackup.sparsebundle
 
*/
 
#include
#include 
 
int main (int argc, const char * argv[]) {
 
   if (argc != 2) {
        printf("Usage: %s [sparse bundle directory]\n", argv[0]);
        printf("Sets extended attributes for sparse bundle disk image\n");
        return 0;
   }
   int sxr;
   int options = XATTR_NOFOLLOW;
   char theValue1[] = { 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00};
  char theValue2[] = { 0x59, 0x48, 0x60, 0x38,
            0x65, 0x7C, 0x09, 0x22, 0x33, 0xAD, 0xA5, 0x73,
            0x12, 0xAD, 0xF3, 0x7F, 0xEE, 0x90, 0x5B, 0x92};
 
   size_t   theSize1 = sizeof(theValue1);
   size_t   theSize2 = sizeof(theValue2);
 
   sxr = setxattr(argv[1], "com.apple.FinderInfo", (void *)theValue1, theSize1, 0, options);
   sxr = setxattr(argv[1], "com.apple.diskimages.fsck", (void *)theValue2, theSize2, 0, options);
 
   return 0;
}

Make OSX’s top behave like Linux’s top

OSX’s top program doesn’t quite behave like its Linux counterpart out of the box. For me, the two biggest problems are that processes aren’t sorted by CPU usage and the top program itself uses 10% of the CPU because it calculates all sorts of statistics about memory and shared library usage that I personally don’t care about.

There are a series of flags that you can pass to OSX’s top to have its behavior be closer to Linux’s top. I have created the following alias to that effect :

alias mytop='top -s1 -o cpu -R -F'

The display is updated every second, processes sorted by CPU usage and no unnecessary statistics are calculated. Instead of 10%, top uses only 2% of the CPU.

Achat de musique en ligne? Finalement oui!

Je refusais systématiquement de considérer l’achat de musique en ligne pour deux simples raisons :

  1. Protections DRM (détails sur Wikipedia)
  2. Mauvaise qualité d’encodage

Avant hier, j’ai découvert une artiste dont la musique semblait intéressante. Comme j’essaye toujours d’encourager les artistes inconnus qui tentent de percer et que c’était en plus une Québécoise, j’ai décidé d’acheter son CD. Mais pourquoi devoir encombrer mon étagère d’une autre pochette que je ne retoucherai plus jamais après avoir copié le CD sur mon laptop ??

Ce n’est pas le scoop de l’heure, le service étant disponible depuis 2007, iTunes offre une partie de son catalogue en format Plus, ce qui signifie des fichiers libres de DRM et encodés en AAC 256kbps, un niveau de qualité largement suffisant.

En deux clics et 9.99$ plus tard (au lieu de 13.99$+taxes en magasin), je téléchargeais le CD à 1MB par seconde. Moins d’une minute plus tard, j’étais donc en train de profiter de ma nouvelle musique en ayant sauvé de l’argent et en ayant diminué mon empreinte écologique par rapport à l’achat d’un vrai disque.

Un achat concluant. Ce sera probablement comme cela que j’achèterai toute ma musique à l’avenir, tant que les maisons de disque consentent à vendre leur musique libre de DRM. Vérifions quelques artistes québécois sur iTunes :

  • Dumas : aucun album en format Plus.
  • Les Cowboys Fringants : seul l’Expédition est en format Plus.
  • Pierre Lapointe : aucun album en format Plus.
  • Ariane Moffatt : aucun album en format Plus.

Google Trends

Je suis tombé sur un outil très intéressant de Google Labs hier : Google Trends.

With Google Trends, you can compare the world’s interest in your favorite topics. Enter up to five topics and see how often they’ve been searched on Google over time. Google Trends also shows how frequently your topics have appeared in Google News stories, and in which geographic regions people have searched for them most.

Quelques graphiques intéressants :

Des heures de plaisir en tout cas.

Useful free Mac apps

I’m a relatively new Mac user so I’m keeping a list of some useful free apps that I’m using on my Mac. It’s a work in progress…

  • Instant Messaging : Adium
  • PDF Annotation : Skim
  • Notes taking : Freemind
  • Linux package manager : Macports (lots of my friends use fink)
  • EquationService : Create equations from latex that can be used in Keynote
  • MacFUSE : MacFUSE is software that allows you to write arbitrary file systems as user-space programs
  • Creative MP3 Player support : XNJB
  • OSX Ext2 Filesystem
  • Switch : Audio file converter
  • Cyberduck : SFTP/FTP
  • Espérance DV : Create a ramdisk