How-To: ‘Gray out’ Files in Finder

When copying files in Finder, you might have noticed that the newly created, still-being-written-to files are ‘grayed out’, conveniently informing the user that the file is not ready yet.

'Grayed out' file in Finder

I wanted to replicate that for an upcoming upgrade of Transloader (along with a progress indicator, as you can see in the screenshot above, but that’s another topic), and after trying a couple of things, I found out how to do it.

I tested this on macOS High Sierra only, since it’s the OS version I’m targeting right now, but I don’t see a reason why it wouldn’t work on earlier versions of macOS.

It’s All in the Date

After digging around on the internet, I found that all that needs to be done is to change the file’s creation- and modification dates to one specific date, namely:
January 24th, 1984, 09:00:00 AM

Source code for setting the creation- and modification dates of a file

And it works great – the created file appears ‘grayed out’ in Finder.

There’s a downside, however:
When copying a file in Finder, and trying to move that still-being-written-to file, Finder will display a convenient message that tells the user the file is in use and moving it might cause problems.
This doesn’t happen when using this date-setting approach.

So I kept digging.

The Solution

What I did, then, was use Terminal and the ‘mdls’ command to list the meta data of the still-being-written-to file:

Using the mdls command in Terminal

At first, coming from the date-approach, I noticed the kMDItemFSCreationDate item, stating
1904-01-01 00:00:00 +0000

However, setting that as the creation date does nothing at all.

Then, I noticed the kMDItemFSCreatorCode and kMDItemFSTypeCode fields (red arrows in the screenshot of Terminal above).

Setting those like this…

Setting the creator- and type codes in code

…does exactly what I wanted – it ‘grays out’ the file in Finder, and displays the convenient Finder error message when trying to move it:

Finder error message when trying to move a still-being-written-to file

Mission accomplished – we’re done!

Please keep in mind, though, that the user may still choose “Continue” to move the file, so you should definitely use an NSFileCoordinator to take care of that.

Advertisements

Mac Developer Tip: NSTouchBar in a Share Extension

You’re working on your Share extension with support for MacBook Pro’s Touch Bar, but it’s empty and doesn’t appear when your extension is loaded?

NSTouchBar Empty

The solution is simple:

Solution for showing NSTouchBar from within a Share extension

Call [self.view.window makeFirstResponder:self.view]; and it will push your glorious NSTouchBar onto the stack:

NSTouchBar working in a Share extension

Hope it helps – it would have saved me 20 minutes if I’d known ;)

Eternal Storms Software Logo

– – – Do you enjoy my blog and/or my software? – – –
Stay up-to-date on all things Eternal Storms Software and join my low-frequency newsletter (one mail a month at most).
Thank you :)

iTunes Affiliate Program – One Year In

Last year, I started using the iTunes Affiliate Program.
The program allows you to make a little money by linking to your apps with your affiliate token and lets you track where clicks and purchases come from, as well.
I thought it’d be interesting to do a little retrospective, now that a year has gone by.

Using Affiliate Links

Turning an (Mac) App Store link (or almost any other iTunes – based link) into an affiliate link couldn’t be simpler.
All you need to do is append your affiliate token (like &at=your_token).
Additionally, you can provide context with your links so you can track them more easily later on.
For instance, I “tag” my links with “twitter”, “facebook”, “blog”, “website”, “newsletter”, “yoinkdemo” and so on.
That makes it very easy to track where your customers come from.

I use affiliate links for every iTunes link I share – be it an app of my own or that of another developer.

Tools and Info

There are tools available to you to make affiliate linking even easier, like John Voorhees’ Blink (for iOS).
I personally don’t use any extra software – I have a note in Notes.app with all my affiliate links and then just change the aforementioned context string.

If you’re interested in an in-depth look at the iTunes Affiliate Program, I recommend you read John Voorhees’ excellent comprehensive guide about it on MacStories.
It’ll get you up to speed on how to set it all up.

Where do Clicks Come From?

A very interesting aspect of the iTunes Affiliate Program is its tracking capabilities.
When someone clicks your link, you know:

  • the country the user is in
  • when the link was clicked
  • the context string you provided for the link (like “website”, “blog”, etc)
Live-View of Clicks on Links

A click presented in the live-view of iTunes Affiliate Program’s dashboard. I can see the click came from the US, and from within Yoink‘s “Demo Expired” window.

Furthermore, it tracks what the user purchased – a Mac app, an iOS app, a song, a book, etc.

Top 5 Countries

Based on the number of clicks, the top 5 countries from where people click on my links are:

  1. United States
    22,498 clicks
    $254.15
  2. Brazil
    924 clicks
    $4.96
  3. Germany
    570 clicks
    $76.70
  4. United Kingdom
    91 clicks
    $46.10
  5. Spain
    50 clicks
    $19.17

Apparently, more clicks don’t automatically equal a higher payout.

Conversion Rates

The program allows you to see the conversion rates for your links.
Who really purchased after clicking my link? Here’s what I found out:

  1. 38.62% purchased an app after clicking a link on my website
  2. 25.70% purchased an app after clicking on the link from the “demo expired” window inside the app
    (I haven’t had the affiliate link in the “demo expired” window in Yoink for the entirety of the year, more like only half a year)
  3. 00.72% purchased something when they clicked on a link on my blog

I can’t be sure what the user purchased – once a user clicks a link with an affiliate token, that token is used for the next 24 hours for that user.
Which means that they might click on a link for Yoink, but don’t purchase it. Then, some hours later, they purchase a book on the iBook Store – that will count towards that link’s conversion rate.

A Year of iTunes Affiliate Program Links

Here’s the gist of my first year in the iTunes Affiliate Program:

  • Clicks: 24,647
  • Items Bought: 4,465
  • Revenue Generated: $ 9791.12
  • Payout: $ 685.38
  • Average Conversion Rate: 18.12%

Granted, $685.38 isn’t a lot, but it’s money I wouldn’t have seen otherwise, and as an indie developer, every bit counts ;)

Eternal Storms Software Logo

– – – Do you enjoy my blog and/or my software? – – –
Stay up-to-date on all things Eternal Storms Software and join my low-frequency newsletter (one mail a month at most).
Thank you :)