Category: Software


Getting Info From iTunes

May 19th, 2017 — 12:35pm

Things have settled down with my 4.1 release so I thought I’d tend to my neglected blog.

Today, I’m going to talk about getting info about your iTunes library, playlists and albums.

Now, the obvious way to do this would be through AppleScript/AppleEvents. The problem with this approach is that it requires iTunes to be running for it to work. To actually change stuff in your iTunes library, you will have to use AppleScript but for the purposes of this article, we are just looking at ways to get information about it.

The old way to do this was to parse the iTunes Library.xml file (located in ~/Music/iTunes). This file contains a dump of everything you need. Unfortunately, recent versions of iTunes do not generate this automatically; you have to enable it in its preferences (it’s in the “Advanced” tab).

Now, the notion of having to parse an XML file does sound painful but luckily it’s actually a property list so you can load it that way and access everything as NSArrays, NSDictionaries, NSStrings, etc.

With OS X 10.9 (yes, I know it’s macOS now but back then it was still OS X), Apple introduced the MediaLibrary API (ML). This provided a way of not just accessing the iTunes library, but the libraries of all of Apple’s other media apps (Photos, GarageBand, even Final Cut). No parsing involved but it is a fully asynchronous API so expect to deal with a lot of callbacks.

The last one (I don’t know exactly when it was released but it was the last one I discovered) is iTunesLibrary (ITLib) and it’s a bit easy to miss because, from what I can tell, it is not a part of the OS, but iTunes itself. You can find the framework under /Library/Frameworks (not /System/Library/Frameworks). It provides similar functionality to the MediaLibrary framework, but specific to iTunes.

With so many options, which do you use? For the most part, they return the same information though it depends on the version of iTunes. With some versions, one API may return some special playlist that the others don’t. Also, ML is asynchronous while the others are synchronous. I don’t see that as a big deal either way as you can convert one into the other with a tiny bit of work.

The big differentiating factor is performance. Here are the results for getting a list of playlists for my library:

XML: 1.664939s
ML: 18.792855s
ITLib: 0.844415

I don’t think my library is the biggest in the world but it is significant (about 2000 albums). As you can see, ML is pretty damn slow with ITLib being much, much, much faster. What is surprising to me is how much faster parsing the XML file is than ML. It is possible, though, that I’m holding it wrong.

So, ITLib is my recommended API for this. It’s what Hazel uses starting with 4.1 (previously, it was parsing the XML when it was available and falling back to ML). That said, there is one wrinkle.

The persistent IDs of entities in iTunes are hex strings. In the XML file, they are zero padded. In ML, though it returns strings, they are not zero padded (rdar://26624642 for you Apple folks watching from home). To add even more confusion to the mix, they are NSNumbers in ITLib.

If you are using any of these APIs in isolation then it’s probably not a big deal, but if you want to later manipulate that entity using AppleScript (like importing files into a playlist), you will need to provide the zero-padded hex string. Something to keep in mind.

Comment » | Cocoa, Hazel, OS X, Programming, Software

Ten Years

September 6th, 2016 — 7:00am

Today marks the 10th anniversary of Hazel. On September 6, 2006, Hazel 1.0 was released and after all this time, it’s still going strong. I’ve already shared my thoughts on why I took this journey and how I managed to stay on this road so I won’t rehash that here. What started as a product developed in my bedroom is, well, still a product developed in my bedroom, but now I can say it’s a successful one.

Hazel back then was a much more basic product. You can check out the release notes page, which documents everything back to the beginning. It’s interesting to see what features were added later, many of which are probably considered essential now.

As for the future, who knows? While the list of big features I want to implement is much shorter now, there are still a bunch of smaller things I want to put in. I can’t say whether I’ll still be doing this in another ten years but I have no intention of quitting now.

And with today being the anniversary, I need to celebrate in some way so, from today until 3am (EDT) tomorrow (Sept. 7), I am offering Hazel at its original price from 10 years ago. That’s $16 (50% off). The family pack and upgrade didn’t exist back then but they’re 50% off as well. No special code or link. Just go to the store and buy. If you don’t have a copy yet, here’s your chance.

2 comments » | Business, Hazel, Noodlesoft, Software

Cleaning Out Turd Files

May 17th, 2016 — 12:37pm

A little pet peeve of mine are the turd files that Emacs leaves behind all over the place.

For those that don’t use Emacs, when you edit files with it, it will keep a backup of the original file in a file with the same name, except with a tilde (~) at the end. The problem is that you have to manually clear them out. When you are jumping around in Terminal editing config files left and right, trying to get something working, you tend to forget where those files are. And yes, you can turn that off, but I like having the backups and yes, you can specify that it store its backup files in a common place but it makes it harder to recover files should I need to check the backup version, especially when I’m editing a bunch of files with the same name (index.php anyone?).

Since Hazel before version 4 only operated on actual folders/directories in the filesystem, it couldn’t really handle cases like this where the files are strewn all over the place. Now with Smart Folder support, you can create one to match all the turd files and have Hazel clean them up for you. Here’s a Smart Folder and Hazel rule you can use yourself:

Turd Cleanup

One important bit about the Smart Folder conditions is that I use “Filename” and not the more readily available “Name” or “File extension” attributes as the ~ is tacked onto the end regardless of whether there is an extension or not.

And of course, no reason to limit it to Emacs turds. Go ahead and edit the Smart Folder to include whatever other poops you have on your system.

Comment » | Hazel, Software, System Administration

Hazel 4 Development/Launch Post-Mortem

May 5th, 2016 — 7:37pm

It’s been a bit hectic because of the launch yesterday but I finally have a moment to post. Yes, Hazel 4 is finally out. You can find the release notes here.

Development was a bit rocky. I played with a bunch of different features but some of them didn’t quite pan out in a way that I liked. It felt like wasted effort in that that work didn’t result in a usable feature but many of them were only shelved temporarily. Oftentimes I end up having that eureka moment which would allow a shelved feature to be finally realized so something to look out for in future point releases.

That said, I’m happy with the features that I did get to work. They seem simple on paper but involved a bit more thought than would be expected. Sync is always tricky and getting the preview feature down to something as simple as it is now took a little doing.

Along with that was the site re-design (courtesy of the folks at Brotherhood). The previous site was mostly static. Adding content involved editing raw html pages and adding them. It was enough to discourage me from doing it often and discourage me it did, as I ended up leaving the site very outdated. The new site is backed by WordPress which will hopefully remedy that. The point here being that content can be added more easily using tools like MarsEdit or WPs web editor. I’ve already added a few posts (a review and a couple of knowledge base articles) since the launch.

Also, the new site design is a bit more stripped down and streamlined. I’ve tried to reduce navigation in favor of search. Most of the site is searchable via the form on the support page so I recommend going there first and doing a search if you ever have a question about Hazel.

 

The launch itself went relatively smoothly (except one incident – more details below). I can credit most of this to using a VPS (virtual private server). VPSes are great as you can clone, rebuild and resize them as needed. It gives you an amazing amount of agility when deploying servers.

Before the launch, I set up a clone server so I could set up and test the new site. Since it’s a clone, no need to reinstall and reconfigure everything (though you do have to make some changes in places where the IP address or hostname is stored). You end up with pretty much an identical server to play with which went a long way towards making sure things were working properly.

When I launched, I transferred the new stuff over to the live server. That part went with little drama but then disaster happened: I underestimated the load from tons of eager customers. The problem was that I had sent two email campaigns. One to those on my mailing list and another to those who purchased recently. The latter group received a message with instructions on how to get their free upgrade license. And guess what all those people decided to do immediately upon seeing that.

The result was that the site got slammed. More specifically, apache was overloaded. Enter VPS awesomeness #2: I was able to resize the server on the fly. It took a little while (maybe 15 minutes though it felt much longer) but the old server was still able to run, albeit very sluggishly, until the last minute when the conversion finished and it rebooted. After that, the site ran like butter and it was smooth sailing (at least as far as the server went).

 

Aside from some minor glitches (version 4.0.1 released this morning should address some of them), the launch has been pretty great. I just had the best day in sales in Hazel’s history so I’m pretty happy about that. My thanks to everyone who contributed, including Brotherhood, Jono Hunt for his icon and UI work, my beta testers, my friends in the Mac dev community and of course, all my customers who’ve been very supportive of Hazel all these years.

Comment » | Business, Hazel, Software, System Administration, Web

Hazel 3.3.8: Getting Past The Gates

April 5th, 2016 — 12:13pm

In case you haven’t been keeping up with the Twitter feed or the forums, Apple introduced a glaring bug in Gatekeeper in 10.11.4. Any non-app bundles (that includes preference panes, screensavers, plugins, etc.) are rejected by Gatekeeper regardless of whether they are signed or not. For those of us that ship such bundles, this is what I’d consider a big deal.

The workaround itself isn’t so bad: either right-click and select “Open” or drag the pref pane into System Preferences. For users curious enough to email support, it’s not such a bad thing as I can suggest one of the workarounds. The problem it gives new users installing it for the first time a bad impression of the software, not realizing that it’s actually Apple’s fault. I can’t really measure this type of thing but I think it’s safe to say a good number of them just nope out of there without contacting me. The result is that my software has an association with being untrusted.

Daniel Jalkut gives a more detailed account of the mechanics of it here so I won’t go retread that ground.

After filing a DTS incident, Apple confirmed it as a bug (I’ve filed rdar://25466753). There was no information about when a fix would be made available and given that Apple is not known for being nimble about these things and that I was losing customers, I followed the advice of some colleagues and took matters into my own hands.

The result is that starting with Hazel 3.3.8, it will ship with an installer app. The installer app still goes through System Preferences as I still think that its installation process works well. Note that an installer package was also an option but I couldn’t figure out if/how to make it use a previous install location if the software was already installed (If anyone knows, I’d be happy to hear about it just in case I have to resort to it in the future). Hopefully now I can direct my efforts back to getting Hazel 4 shipped.

One can debate how much Apple cares about non-app-bundled software but when the workaround is to suggest people bypass Gatekeeper, they should be very concerned. False positives only erode the confidence people have in your security systems and you don’t want them to get in the habit of casually bypassing them.

4 comments » | Hazel, OS X, Software

Hazel 3.3

October 20th, 2014 — 2:41pm

Hazel 3.3 is finally here. It has a bunch of neat additions that I think experienced users will find handy (in particular, all the things you can do with custom attributes now). I won’t list all the features here but check out the release notes if you want to learn more. Also, while 3.2.7 for the most part works fine on Yosemite, this version fixes all those pesky cosmetic issues, including the dark mode menubar icon which a lot of people seem to be fixated on. I think this is a great release as it ties up a bunch of loose ends and really opens Hazel up to workflows that weren’t able to be accomplished before without the aid of custom scripts. Speaking of which, Yosemite introduced JavaScript  alongside AppleScript as a way to automate apps, so JavaScript is now an option in Hazel as well. So for those of you who find AppleScript unpalatable, now you have an alternative.

While I will continue to do maintenance releases, my thinking at this point is that 3.3 will be the last of the version 3 series as I start shifting into thinking about version 4. I think version 3 has had a phenomenal run and I hope to make version 4 a worthwhile upgrade. It’ll be a while so for those fearing version 4 around the corner, you should’t worry. I’d be quite surprised if I get it out before the end of 2015.

Many thanks to all the testers who banged on 3.3 during its beta. Got a lot of great bug reports including some at the last minute which helped to make Hazel not explode (at least not yet – if yours does, blame it on tester #347).

Enjoy.

1 comment » | Hazel, Noodlesoft, OS X, Software

My NSConference talk

October 14th, 2014 — 1:51pm

Just found out this weekend, somewhat belatedly, that my talk at NSConference 6, “Life Outside the Mac App Store”, is available on Vimeo. I don’t have the nerve to watch it myself but given recent events, you might find it interesting.

Comment » | Business, Conferences, Hazel, Noodlesoft, NSConference, OS X, Software

Hazel in Books

June 27th, 2014 — 12:24pm

It’s nice to see Hazel in books. Even in digital form, the book format gives me more of a sense of permanency than say articles on some site. So, when I see Hazel mentioned in a book, I can’t help but think of Hazel as being a more permanent fixture in people’s computing lives. The most recent entry is Joe Kissel’s book “Take Control of Automating Your Mac” which has a little section talking about Hazel. While most readers of this blog are already familiar with Hazel and Mac automation in general, this book is a great introduction for the novice in your life who is ready to delve deeper into their Mac. It also contains coupons for many of the apps mentioned in the book.

And on the topic of Hazel in books, I’m way overdue in mentioning “Mac At Work” by David Sparks. This came out a while back but is a great intro to using your Mac in a work environment. Also, it’s available as a physical book, which is always useful for propping up an uneven couch leg (after you’ve read it, of course).

I’m still waiting for Hazel to be incorporated into some work of fiction. Too bad Stieg Larsson isn’t around anymore as he had a tendency to go into way too much detail about characters’ computer configurations.

Comment » | Books, Business, Hazel, Software

Understanding OS X Betas

June 3rd, 2014 — 12:41pm

With OS X Yosemite going public beta, I feel that it’s important that people understand what that entails. This happens almost every year but it seems worthy of a reminder.

Beta is the development phase where the product is not finished but ready to be tested. Operative term: NOT FINISHED. What does this mean to you?

  • There Will Be Bugs
  • Many apps will not work.
  • Things may be slow.
  • You may lose data.
  • Issues will be addressed on the developer’s schedule, not yours. Even until some time after Yosemite is released, apps may not be ready yet.

In short, if you use your machine for any type of important work, DO NOT INSTALL THE BETA. It’s not our, or Apple’s, fault or responsibility if you are unable to get anything done because you didn’t heed this advice. If you must install it, in the very least install it on another drive/partition or virtual machine (VMware, Parallels, etc.) so it doesn’t impact your main installation.

And remember the purpose of the beta is for the developer to test their product, not for you to get a sneak peek at what’s new. If you find a bug, report it to the developer. And I mean REPORT it. Do not instead:

  • Talk about the bug on some site that the developer will not see.
  • Review an app running on a beta OS or is in beta itself.
  • Tweet a complaint with few details (Twitter is horrible for bug reporting).
  • Stay quiet about it and assume the bug will be magically fixed.

If you really care about the bug getting fixed, then tell the developer directly, providing necessary details. If possible try and figure out if the bug is Apple’s or ours and email the appropriate party. In general, during the early beta stages, the bug is probably Apple’s. Near the end, it’s probably ours. We do want to fix things but not reporting them properly is counterproductive to that.

With everyone’s cooperation, hopefully the transition to Yosemite will be a smooth one. Ok, maybe not, but at least I tried.

1 comment » | Business, OS X, Software

ConnectionKit

July 10th, 2013 — 10:58am

In Hazel 3.1, I added the ability to upload files. Underneath the hood, I used ConnectionKit 2 to do the heavy lifting. It has an API similar to NSFileManager, making it very easy to add FTP, SFTP and WebDAV support without having to deal with the pesky details of those protocols. There were other factors on why I chose it, such as the fact that not only is it actively developed, but done so by people who use it in their own shipping commercial products. And it didn’t hurt that it’s maintained by my friends at Karelia.

If you have used this feature in Hazel, you would have encountered this interface:

ckopenpanel1.png

It should look a bit familiar. It’s a homegrown, from scratch, implementation of NSOpenPanel made to work on top of ConnectionKit. I felt it important to provide a familiar interface instead of coming up with something new in this case. I did a bit of work to make sure it operated as closely to NSOpenPanel as was reasonable. It has multiple view types (icon, list, and column) and most of the controls you’d expect.

Of course, browsing a filesystem via various network protocols is a different beast so some things had to be done differently. The main thing is that the UI is asynchronous from the network stuff so no beachballing while waiting for responses from the server. The UI should be responsive at all times, even allowing you to cancel the panel at any point. In the upper right, there’s a reload button that changes to a progress indicator to indicate activity and you will see a loading message when trying to fetch the contents of directories that haven’t been loaded yet.

Visually, the biggest difference is the header up top noting which server is being browsed. Also, the sidebar is missing. There aren’t many standard locations that can be put there and I felt that favorite URLs should be managed elsewhere as it didn’t seem likely that users would want to hop from server to server by clicking different entries in the sidebar. The one common directory that I could think of was the home directory and so instead, I gave that its own button (note that not all servers/protocols have such a concept of a home directory and it also depends on what URL you use to connect to the server so YMMV).

Another omission is the search field. Since there’s no notion of Spotlight in any of these protocols, doing an exhaustive search of the remote filesystem would be resource intensive and not very friendly to the servers involved. While I may consider adding it back in to search the current directory, you can get much of the same effect by just typing out the name of the file. Just as in NSOpenPanel, it will end up selecting the entry starting with those characters. I also dropped the Arrange button and the Coverflow view, mainly because I didn’t think people actually used those things. Especially for Coverflow, it wouldn’t be particularly useful since we can’t get file previews without downloading the whole files themselves.

But besides all of that, I think you’ll find it to be a pretty decent facsimile of NSOpenPanel. You might be surprised by how much of NSOpenPanel’s behavior is replicated here, including some features many people don’t know that NSOpenPanel has.

And the resemblance is more than skin deep. CK2OpenPanel (the name of the NSOpenPanel implementation) has a nearly identical API to that of NSOpenPanel. It’s a mostly drop-in replacement for NSOpenPanel so programming to its API should be just as familiar. Why would you care? Well, you should care because I’ve contributed the code for CK2OpenPanel to be included in ConnectionKit. You can see all the code, warts and all. Play around with it. Use it in your own projects. Print it out and wallpaper your home with it. I felt it was the least I could do for all the work that’s been done on the backend. Also, I thought it would be nice if people adopted it so that there was a standard UI for this type of thing.

You can find everything on the ConnectionKit GitHub page. In particular, you want to check out the v2.x-beta branch. Note that there are separate targets/frameworks in the project for the back end (ConnectionKit) and front end (ConnectionKitUI), with the latter dependent on the former. Make sure to check out the README as it should answer a lot of your questions. And if you are interested in contributing to ConnectionKit, please do as there are a bunch of things that need work. S3 support would be nice, for instance.

Last but not least, a big thanks to Mike Abdullah at Karelia for working with me to provide the backend support for this. Rest assured that he will be receiving beers from me at the next conference we both attend.

Enjoy.

Comment » | Cocoa, Downloads, Hazel, OS X, Programming, Software, User Interface

Back to top