Monday, March 14, 2011

Solved: Mac Finder Crashes Upon Opening A Certain Folder Repeatedly

I experience this today. I had never heard of it before. It blew my mind at first. I thought my whole system was crashing down. Alas, it's a minor issue.

After googling some I wasn't able to find an absolute cause or solution. After some tests I discovered the cause, and a solid solution.

The cause: unreadable or corrupted extended attributes in one of the files or folders which prevents Finder from properly handling and displaying the folder contents.

The solution - remove the extended attributes on the the folder contents. I didn't know which file or folder in the affected directory was the cause, so I removed all extended attributes on all items and the problem was solved.

To do this:

1. Open terminal and go to the affected folder.
2. ls -al@e  to show the extended attributes on the folder contents.

Copy one of the attribute names and remove it from all items, for example ''

3. xattr -d *  will remove this attribute from any items that have it.

Repeat step 3 for all attributes, one at a time. For example, I had to run:
xattr -d *
xattr -d *
xattr -d com.macromates.caret *
xattr -d *

That was it. Then my Finder displayed all items properly and stopped crashing.

Other responses from Google results recommended deleting .DS_store files or restoring the directory from a TimeMachine backup. Don't do any of that. It doesn't fix this issue. Only removing the extended attributes will solve this issue.

Saturday, March 12, 2011

Javascript Goodie - Smart Load JS/CSS Linked Files on First Ajax Request Only - Not on Subsequest Requests.

I've experienced an issue on many occasions where a feature of a website needs to load some advanced ui functionality via ajax onto a page and link additional css and/or js files with the ajax request in order to accomplish it. This feature may be requested numerous times while completing some sort of set-up, whatever. The repeated loading of the same css or js files is an unnecessary bandwidth hog and may slow the user experience considerably, as pop-up modals are expected to be snappy. In some cases this repeated reloading of the same linked files might possibly cause javascript errors as the repeated overloading of javascript functions overwriting the previous instance in the browser memory each time the js file is reloaded with the ajax request.

This is my solution. I had googled this issue on random occasions and found a couple hints here and there in the direction of what I wanted to accomplish, but no solid solutions presented themselves. So, I wrote my own solution. It was a lot simpler than I originally expected.

This example relies somewhat on jQuery, but it could be rewritten without it.

    function smartLoad(flist){
        if(flist.length==0){return false;}
        var flistArray = flist.split(',');
        for(i in flistArray) {
            var f = $.trim(flistArray[i]);
            if(window.smartLoadList.indexOf(f)==-1) {
                if(f.substr(f.length-2,2).toLowerCase()=='js') {
                    $("head").append('<scr'+'ipt src="'+f+'" type="text/javascript"></scr'+'ipt>');
                } else if(f.substr(f.length-3,3).toLowerCase()=='css') {
                    $("head").append('<li'+'nk rel="stylesheet" type="text/css" href="'+f+'" />');
                } else {
                window.smartLoadList = window.smartLoadList + "," + f;
    $(document).ready(function() {
        smartLoad("/css/custom.css, /javascript/c1.js, /javascript/c2.js");

That's a wrap!