The last couple of weeks I've working on the export of tags and comments to Spotlight. This has been much more complicated than I expected. Nifty Box now writes the tags or comments to the Spotlight Comment field in the Finder's "Get Info..." window (for file items). This is a bit tricky.
First of all only the Finder can edit this field, which means one has to use AppleScript or AppleEvents. This is ok, there exists some source code from Apple (MoreFinderEvents) to do this. But during the testing sometimes strange things happened: for long comments written to this field it seems, that the Finder looses information about all the comments and icon positions in the folder of the changed item. After some experimenting I found, that the Spotlight Finder comment is written to the hidden .DS_Store file in the folder of the specific file. The .DS_Store contains all specific Finder information (like icon position and Spotlight comments) of all the files in the folder. But this information is somehow coded in blocks, which means that there is a maximum length set implicitly for the Spotlight comments. If you try to save a longer comment, the .DS_Store gets corrupted. By trial-and-error I concluded, that the combined length of the comment plus the length of the filename must not be greater than 1012 UTF-16 characters. Nifty Box will deal with this. For web bookmarks I dont use the Spotlight comment field, but provide an own Spotlight importer, which is much more convenient.
The way the Spotlight finder comments are used by Nifty Box is as follows: first all tags are written into the field, whereby these can be prefixed by a special character like "|" or "&". If you choose to use such a prefix, the Spotlight search can be narrowed down only to the Nifty Box items. An example: if you like to search in Spotlight for items tagged with "Apple" you would get a zillion hits if you just type in "Apple" in the search field, because - as you might guess - the word "Apple" can be found quite a lot on the mac. But if you only want to view the Nifty Box items, tagged with "Apple", you can define just a tag prefix like "|" and search in Spotlight for "|Apple" which should only give you the Nifty Box items.
After the tags you can choose to export your notes too. At the end a marker "_nybx_" is inserted into the comment field. After this marker the original comment from the Spotlight comment field is preserved. If the complete string (Nifty Box additions plus original comment) gets too long for the .DS_Store file, the Nifty Box additions will be shortened leaving the original comment complete.
Just to give you an impression, here is the new preferences tab for the Spotlight Export settings:

This will export a Spotlight Finder comment like this:

And here is an example Spotlight search for the tag "Mars": (please note the prefix "|")
In the screenshot you can also see the tagged web bookmarks at the top, which are provided by an Spotlight importer and not via the Finder's Spotlight comment field.
Using the Finder's Spotlight comment field for the file items also gives you information directly in the Finder if a file is tagged by Nifty Box: you can activate the "Comments" table column in the Finder window, which will show you the tag information for all files in a given folder:

So this export functionality is now implemented and in beta test. I am now working on the second new feature for version 1.1. I hope I will finish the development in December such that the new version can be released at the beginning of the new year.
Labels: NiftyBox