Posts Tagged osx
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; }
trafshow : Display current network traffic
Posted by mailletf in Technology on February 26, 2009
trafshow is a simple little program that displays the current traffic on a network interface.

It listens on a given interface in promiscuous mode and displays information on each connection, its remote address and the amount of traffic going back and forth.
It can easily be installed on a Mac via Macport.
Make OSX’s top behave like Linux’s top
Posted by mailletf in Apple, Technology on January 24, 2009
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.
Using filemerge for mercurial diffs
Posted by mailletf in Programming on January 8, 2009
A friend of mine found a script that brings up OSX’s FileMerge program instead of the text-based file comparisons you get with mercurial with doing an “hg diff”.
- download this script and make sure its location is in your PATH
- add the following to .hg/hgrc:
[extensions] hgext.extdiff = [extdiff] cmd.opendiff = fmdiff
- Now type hg opendiff <filename> (hg op is enough), instead of hg diff <filename>
SQLite3, php5 and MAMP
Posted by mailletf in Apple, Programming on December 1, 2008
To make this short, php5 doesn’t come with sqlite3 support out of the box. My setup is as follows :
- SQLite3 installed through MacPorts
- php5 used through MAMP
I used the php-sqlite3 extension. When you run phpize, make sure you are actually using the one from MAMP by calling it with its full path /Applications/MAMP/bin/php5/bin/phpize.
I then complied the extension with the following flags (both paths are the defaults for macports and MAMP) :
./configure --with-sqlite3=/opt/local/ --with-php-config=/Applications/MAMP/bin/php5/bin/php-config
The make install didn’t copy the librarie to the right php folder :
>make install Installing shared extensions: /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/
Make sure that folder is the right one. You can find your dynamic extensions folder in your php.ini file
Shrinking sparse bundle images
A sparse bundle image in Mac OS X will grow as you add files to it but never shrink if you remove files inside of it. To reclaim the disk space, you must run the following command :
hdiutil compact path/to/sparsebundle
If your account is protected with FileVault, this is done automatically for you when you logout of your account.
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
Compile against libraries installed with MacPorts
Posted by mailletf in Apple, Programming on January 22, 2008
MacPorts installs packages in a non unix-standard location. This can cause problems when trying to compile other software against these packages because they aren’t found by the configure script.
I experienced that problem when trying to compile SDL_image, which depends on libraries such as libpng. I had to configure with the following flags :
./configure CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib"
which indicates in which folders the libraries installed with MacPorts were installed.