Leopard’s Broken FolderActions facilities

Apple, Leopard, Rant, Tips, Troubleshooting Be the first to Comment

One of the best features of Mac OS X is a feature called ‘Folder Actions’. What this feature allows the power user to do is to watch a folder on the computer and whenever that folder receives a file, folder action kicks in and runs a script of the user’s choosing.

I’ve used this feature for a long, long time. I use it among other things to archive all the files submitted to my main site into a folder tree organized by date. For example a story submitted on April 20th, 2008 will end up in:

/SubmissionArchives/2008/04/20/

I’ve been doing this for years. So long ago that I can’t recall when I started doing it that way; it may have started on Mac OS 9. So needless to say, it’s very useful.

I have few other folder actions set up to do various routine tasks.

But it all came to a halt with my upgrade to Leopard or Mac OS X 10.5.

In Leopard, I couldn’t get folder actions to work with more than one active folder action. If I set up 2 of them, only the second one will work. If I set up three, the third will work and the system will completely ignore the first two. I’ve filed bug reports with Apple, and now at 10.5.2 the problem persists.

This weekend, I’ve had to do something that I rarely do, which is to archive a massive number of files; around 27,000 files at the same time. So what better need for an automated thing other than a massive job?

Well, as it turned out, a massive job is what you don’t want to handle with the current version of Folder Actions.

As soon as I dumped the 27,000 files into the watched folder, my computer (a 2.8 Ghz iMac) slowed down to a crawl. A quick check in the terminal showed that the Folder Actions daemon consuming 100% of one CPU core and the Finder was consuming the remaining 80% of the other core. The funny part is that no files were being moved. After 30 minutes, files started moving at the speed of 1 file every 4 seconds. At that rate, the job would take 30 hours to finish.

But the kicker is that the Finder kept crashing and throwing a dialog about an invalid connection and requiring me to click ‘OK’ in order for it to proceed. So even if I were willing to wait, without constant clicking OK, the job wouldn’t proceed at all.

I worked around the problem by creating a new script that reads the list of files from a flat text file that I created by selecting all the files in the Finder and copying and then pasting into a BBEdit document. So the script reads that text file, line by line and hands the file’s path to the finder and the finder moves it to its destination.

It’s slow, it’s doing about 2 files per second as I write this, so theoretically it should be done in like three hours or so.

I wish I knew more about shell scripting. I’m sure such a job for a good shell scripter would take no time to set up and few minutes at the most to execute. I guess that’s something that I need to add to my arsenal of tools.

And here’s a free tip: In AppleScript’s date function, if you want the number of the month do it like this:

set theMonth to the month of theDate as integer

if you don’t add that ‘as integer’ bit, you always get the name of the month and that bit is not documented anywhere that I could find. I stumbled on it by sheer dumb luck. Page 88 of AppleScript’s language guide gives you this:

month
Access: read/write
Class: constant (page 86)
Specifies the month of the year of a date object, with one of the constants January, February, March, April, May, June, July, August, September, October, November, or December.

But if you you try this:

set theMonth to July as integer

You get 7 back.

Talk about counterintuitive.

Be the first to Comment

Changing the system’s default settings for html files (safe)

Apple, Leopard, Mac, Tips, how-to 1 Comment

With Leopard 10.5.1, Apple’s developers changed the default status of html files downloaded from the internet from ’safe’ to ‘Unsafe’.

While this may make sense from a security standpoint, for somebody like me that processes hundreds of html files downloaded every day, it’s a big annoyance.

I filed a bug with Apple, asking for a workaround. I was hoping that they would implement a preference somehow to enable me to either override the default settings or allow me to specify trusted servers.

Tonight, three months later, I received an answer and the workaround that I was looking for.

I turned out that you could have a user specific file to override the system’s default settings. The file is not there normally, so you would need to create it. It is:

~/Library/Preferences/com.apple.DownloadAssessment.plist

The contents of the file need to be:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>LSRiskCategorySafe</key>
<dict>
	<key>LSRiskCategoryContentTypes</key>
<array>
	<string>public.html</string>
</array>
</dict>
</dict>
</plist>

Hopefully that helps somebody else with this type of problem.

If you need to change the settings of other file types, here are the system-declared file types:

System-Declared Uniform Type Identifiers

For each type you add another <string></string> item to the above array.

For example, for jpeg2000 files you add:

	<string>public.jpeg-2000</string>

Right below the other <string> line.

For more info on how this works and other variations, you can go to this page:

Modifying Safari Safe Files

1 Comment

iPod Touch fails to connect to Airport Extreme 802.11n

Tips, Troubleshooting, how-to, iPod Touch Be the first to Comment

Over the holidays, I received an iPod Touch as a gift, and let me tell you, that little sucker is extremely useful as an internet device. Keeping tabs on my sites where I could find Wifi is great.

However, a couple of days ago, it stopped being able to access the internet through my home wireless network. My wireless network is created by an Apple Airport Extreme

First I thought that the Touch had a problem. I reset it few times to no avail. And then I discovered that I could connect to an open Wifi point in the neighbourhood; which made things really frustrating. The Airport Extreme had been, up to that point, the best Wifi system I’ve tested.

A couple of days worth of search on Google netted no solution whatsoever.

Out of desperation, I started messing with the Airport’s settings. Lo and behold, changing the Wifi channel from automatic to ‘Channel 9′ fixed the problem.

Update: As it turned out, the airport needed restarting the hard way. After multiple instance of losing contact with the Touch, I unplugged it for 5 minutes and after plugging it back in, I haven’t experienced any problems with the Touch going on the net.

Be the first to Comment

Leopard’s translucent menu bar

Leopard, Rant, Tips, how-to 1 Comment

One of the ugly new interface “features” of Leopard is its translucent menu bar. In my opinion it’s ugly, distracting and serves absolutely no useful purpose. I have no clue why any sane person at Apple would want to implement it.

There have been many complaints about it on the internet since Leopard reached people’s hands; and unlike the shiny Dock, so far, the menu bar has no workaround to fix the problem and make it opaque.

However, I found a very simple solution after two minutes of looking at this annoying eye sore.

It’s simple. Open your desktop picture in any image editor and fill the top 22 pixels with white. Now because the system caches the desktop image, the change won’t appear until you log out, or simply go to the System Preferences and through the Desktop & Screen Saver panel, select a different picture for your desktop and then select your original white top image again and done. You’ll have a white menu bar without the visual clutter.

1 Comment

Apache PHP and Mysql on Leopard

Leopard, Tips, how-to 75 Comments

Leopard brings one big change to web developers working with Apache, PHP and Mysql on the Mac. Apache 2 comes with Leopard along with PHP 5.

Here is what to do to restore a test environment.

First, you need to enable PHP.

Apache’s .conf file moved from /private/etc/httpd/httpd.conf to /private/etc/apache2/httpd.conf

Open this file with your favorite text editor and uncomment the line:

# LoadModule php5_module libexec/apache2/libphp5.so

You don’t need to add the mime type for php, because it’s already done for you under leopard. The last line in the .conf file is:

Include /private/etc/apache2/other/*.conf

The ‘other’ directory contains a .conf file for php5. That takes care of the mime type and the index.php configuration for php sites.

If you develop multiple sites and you need virtual hosting functionality, scroll down to the end of the .conf file and uncomment the following:

# Include /private/etc/apache2/extra/httpd-vhosts.conf

That’s all the modification that I had to make to to the httpd.conf file.

Next, you’ll need to setup whatever virtual hosts you have in the virtual hosts file /private/etc/apache2/extra/httpd-vhosts.conf

For example, for each line that you set up in your hosts file like so:

beta-site-1.com 127.0.0.1

You need to make an entry in the httpd-vhosts.conf file like so:

<VirtualHost *:80>
   ServerName beta-site-1.com
   ServerAlias www.beta-site-1.com
   ServerAdmin webmaster@beta-site-1.com

   DocumentRoot "/Library/WebServer/beta-site-1"
   ScriptAlias /cgi-bin/ "/Library/WebServer/beta-site-1/cgi-bin"
   <Directory "/Library/WebServer/beta-site-1">
     Options FollowSymLinks MultiViews Includes
     AllowOverride All
     Order allow,deny
     Allow from all
   </Directory>
</VirtualHost>

One good thing is that the ‘upgrade’ install of Leopard does not mess with your hosts file, so whatever virtual domains you may have set up won’t be affected.

If you had Mysql installed previously, good news too, Leopard’s installer won’t touch it. I found mysqld running just like before the upgrade.

One thing changed with Leopard is the socket for Mysql. It moved to /private/tmp, so you may need to configure your php.ini file to point it to the new location.

To do so, open the file ‘/private/etc/php.ini‘, (if no such file exists, then make a copy of ‘/private/etc/php.ini.default‘ naming it ‘php.ini‘) and edit that.

You have two lines to modify:

mysql.default_socket =

becomes:

mysql.default_socket = /private/tmp/mysql.sock

and mysqli.default_socket =

becomes:

mysqli.default_socket = /private/tmp/mysql.sock

of course, from the sharing pref pane, stop the server and restart it and voila!

75 Comments