Diary of a Mac Virgin

Basically the idea is to document my experience of getting used to a MacBook with OS X Tiger and familiarise myself with Blogger at the same time. That's right, I've never blogged before either.

Friday, November 24, 2006

Spotlight - bright-ish... perhaps?

The blurb about Tiger makes out like Spotlight is the best thing since sliced bread but my investegatory clicks on the little magnifying glass icon up there on the menu bar left me wondering why? It seemed to offer little more than a way of finding things whose locations I should already know if I'd stored them in a sensible place.

I was a little less dismissive after the first occasion on which I found myself wondering "where the heck did I put that letter to the Inland Revenue?". Spotlight found it for me in a trice along with a couple of older letters, a spreadsheet and a .pdf that mention them. By the third occasion on which it had located something that had "slipped down the back of my digital sofa" I had warmed to it quite a bit. It looks more interesting when accessed via the Find option on Finder's file menu as this allows you to specify a number of criteria on which to search.

A big disappointed however was the realisation that Spotlight was not indexing my .php files. Back on the PC (which has now been retired) I sometimes used my programers editor (EditPlus) to search all the files in a given directory (subdirectories too if I wanted it to) to find files where a particular function was employed. Smultron, my editor of choice here on the Mac does not have this facility and sooner or later, I'm going to need it.

My 'Rough Guide' book told me that plug-ins to allow Spotlight to index the files from various additional applications are available on Apple's site, but although there are plug-ins for a number of file types, I found no mention of anything to handle .php files.

A little searching on the web came up with suggestions for modifying the info.plist of the RichText.mdimporter or the SourceCode.mdimporter (installed with the Developer Tools) to deal with php files. I also stumbled accross a suggestion that messing with these without a proper understanding of them was perhaps not a good idea. While I'm inclined to agree with the latter I figured that if this was such a bad idea then hopefully there would be fewer suggestions on the web that it is a solution - a million lemmings can't be wrong, can they?

I didn't get as far as trying it however because many of these suggestions also said that the last step was to tell Spotlight to reindex the files and that this could "take a while". There was something about that suggestion that bothered me so I did a little more searching and came across all kinds of complaining about Spotlight doing an incomplete job. I haven't really gotten to the bottom of it but: Spotlight doesn't search for things when you ask it to search; instead it indexes stuff 'Google style', in the background, ready for when you do want to find something. It appears however that while some actions will cause a file to be indexed, others do not. I've seen it suggested for example that although saving a file causes it to be indexed, copying a file does not - so the copied file will not show in a search. I also get the impression that depending on what else is happening on the computer it could take a while even for a newly edited and saved file to be re-indexed.

It would appear therefore, that while Spotlight can be very useful for finding things, you can't RELY on it to find ALL occurrences. A bit like Google: it might find what you want, and frequently does, but there are no guarantees. Thus I will continue to use it when the question that needs answering is "where did I put x?", however it appears that it is not the thing to use if I want to "find every one of my .php files that makes use of function x so that I don't screw anything up if I change it". I guess I'll have to find something else for that.

Wednesday, November 08, 2006

Automator - First Steps

I've got some .pdf documents, about 300 of them actually, that were used to create a printed catalogue by some friends of mine. I'm helping them to create an online version of the catalogue and amongst other things, we need to extract the images.

The documents are not locked so Adobe Reader (I don't have Acrobat) would allow me to select an image and copy it to the clipboard. The easiest way to get them from there seemed to be by going into Preview and hitting Command-N to create a new file using the image data on the clipboard. I could then rename it and save it as a jpeg however I would then need resize it to make sure that it was no bigger than 300 x 400 pixels. Given that the files probably contain around 3000 pictures I figured that I needed a faster way of doing it.

The problem with something like this is deciding how long to spend researching the possible ways in which to tackle it before you just get stuck in and do the slog. In this instance I figured that it would end up taking a couple of weeks doing it by the above method. It seemed reasonable to me that I ought to be able to at least halve that by using more appropriate tools, in which case spending a couple of days researching is fairly easy to justify.

In fact it didn't take anything like that long to find an interesting looking piece of software called File Juicer which is able to extract images and other 'data types' out of larger files. Amongst other things, it can pull all the images out of a .pdf file is one go. Better still, the author provides instructions on how to use Automator to create a plug-in for Finder such that you can control-click the .pdf and have an option to extract files appear on the menu.

Now I'm not new to scripting and automating things but I'd not yet found time to investigate Automator, Applescript, or any of that stuff. Given that discovering File Juicer had gained me a couple of days I figured that now might be a good time to see what it could do about the rest of the process.

I didn't get very far with it, but then I didn't need to as I very quickly discovered two rather interesting things:

The first is that although Preview does not provide an option to resize images it does make an action available to Automator to 'scale' them.

The second is that you can attach actions to folder so that anything you drop into the folder gets processed by the action.

Thus by attaching the action described to a folder I how had the ability to drag and drop the output from File Juicer that I actually wanted (there are other images in the documents besides the product images that I need), into that folder.

Now of course 'scaling' isn't exactly what I wanted and as I'd noticed that Automator has the ability to import new actions, I decided to take a look what was already out there on the web. There is loads of stuff and it didn't take long for me to find an action called Save For Web which allows you to specify horizontal and vertical 'constraints' for the image i.e. it will resize the image if necessary so that it is no bigger than the stated width and height.

Half an hour of fiddling with automator and I had a system by which I could Control-Click on a .pdf and select the option to extract all the files to a new folder. Drag and drop the images that I want to a new folder, where they are automatically resized as needed and turned into jpegs. I can then rename them ready for upload.

It's not perfect but it took me about half a day and cost $12 for the full version of File Juicer (the trial version puts watermarks on some of the files). I could probably spend another day or two honing this to perfection but I figure that if we get stuck into using it as it is, we can have all the images processed before the week is out and take next week off.