Press "Enter" to skip to content

Category: Apple

Apple and Twitter update

I was gratified to see this report (the day after I wrote my letter) that Apple is indeed “pausing” their advertising on Twitter. (I don’t take any credit for this.)

I can only hope that they don’t see fit to “resume” any time soon, given the present circumstances.

Comments closed

Apple and Twitter

This evening, I sent the following email message to Tim Cook at Apple:

Dear Mr. Cook:

I have been an Apple user since 1981 and a Mac user since 1984; my first iPhone was an iPhone 4, but mostly because AT&T didn’t have good coverage in my home town. As I sit at my desk composing this email, there are eight Apple computing devices literally within arm’s reach, not to mention a couple of HomePods and a pair of AirPods.

Professionally, I wrote my first Mac program in 1984 (for a company mentioned in the first issue of Macworld magazine), and my first publicly released Mac software in 1987. My career path wandered a bit after that, but I have been developing Mac software for pay since 2006 and it has been my full-time job since 2009.

I write all this to establish some bona fides for my long relationship with, admiration of, and support for Apple Inc.

Like many people, I was driven to leave Twitter soon after its change of ownership, disturbed at first by the way he treated his employees and third-party developers, and afterwards by the increasing amount of hate speech and abhorrent messages being posted there, apparently not merely tolerated but encouraged by the new owner.

I have been somewhat dismayed that Apple continues to market itself there, but I am not naive, and I recognize that the goals of a major company are quite different from those of a private individual, and that it is necessary for a company to engage with potential customers on a variety of media.

But now I find myself driven to write this letter in response to news items from the last few days:

… to mention only a few.

I cannot believe that it continues to be in Apple’s best interest to have its valuable brand appear adjacent to such virulent, hateful content. Apparently, the leadership at IBM has reached a similar conclusion. I hope that you and the leadership team at Apple are already giving careful consideration to the effect of continuing to financially support such a platform.

At the top of Apple’s “Ethics and Compliance” page, above your name, is the statement: “We do the right thing, even when it’s not easy.”

I urge you to do the right thing.

Sincerely,

Russell Finn

Comments closed

A pox on everyone’s house

This story appears to solely take Epic’s word about Apple’s response to Epic’s recent actions (and the headline is even worse).  I see no evidence that Apple was asked for a comment, although of course they probably wouldn’t have given one.

Given that Epic has intentionally and flagrantly violated Apple’s terms and conditions, it is not surprising that Apple would be considering revoking Epic’s developer account; they’ve done this before, and with less notice. But it’s hard to agree with framing this as “retaliation” rather than enforcing a contract.

Epic’s actions of deliberately poking the bear, and then crying foul when the bear swats them down, reminds me of the classic definition of “chutzpah”: killing your parents and then throwing yourself on the mercy of the court on the grounds that you’re an orphan. It’s clear that Epic is trying to game the situation by playing things out in the court of public opinion as much as possible. As an Apple developer, I believe that certainly Apple can (and should) do much better by their developers—but Epic’s antics are unlikely to gain them much sympathy among developers, either.

Comments closed

NSFileHandle permission errors

In a macOS programming project I have a command that allows the user to open a file containing some configuration options. This file is a property list, so the contents were being read using NSDictionary(contentsOf:); this method simply returns nil if an error occurs. I wanted to provide more details about the failure than simply “The file could not be read”, so I looked for a Foundation method that would throw an NSError. I settled on FileHandle(forReadingFrom:) and inserted the following code:

    do {
        _ = try FileHandle(forReadingFrom: url)
    }
    catch let error as NSError {
        let alert = NSAlert()
        alert.messageText = "An error occurred while reading the options file.".localized()
        alert.informativeText = error.localizedDescription
        alert.beginSheetModal(for: mainWindow) { (response) in
            if response == NSAlertSecondButtonReturn {
                OperationQueue.main.addOperation { self.resetOptions(nil) }
            }
        }
        return
    }

Then I set up a few test cases, including a file that was owned by another user (with no read permission). To my surprise, the error description implied that I was unable to write the file:

[application icon redacted]

…and while that’s also true, that’s certainly not the error I expected to get.

I looked at the error object in the debugger, and sure enough, the error code was 513 (NSFileWriteNoPermissionError) and not 257 (NSFileReadNoPermissionError). Weird.

Well, I know I’m trying to read the file, and I don’t want to confuse the user, so I changed the catch clause to handle this case:

    catch var error as NSError {
        if error.code == NSFileWriteNoPermissionError {
            error = NSError(domain: NSCocoaErrorDomain, code: NSFileReadNoPermissionError, userInfo: error.userInfo)
        }
        let alert = NSAlert()
        //...
        return
    }

…and that seemed to do nicely. But I can’t find any documentation on whether this is expected behavior or what I might be doing wrong.

Comments closed

AppKit bug in 10.12.2: NSTextField with tabs in text displays incorrectly

UPDATE: The bug described below is fixed in macOS 10.12.4 and the workaround described is no longer necessary (except for backward compatibility).

In a recent macOS project I have an NSTextField that contains text with tab characters in order to display a data table. (The text is an NSAttributedString to which I apply an NSParagraphStyle with its tabStops property set to an array containing a number of right-aligned NSTextTabs.)

The text field was drawn as intended (with the text aligned to the tab stops) before upgrading to 10.12.2. After upgraded, the text was no longer aligned to the tab stops, and when using monospacedDigitSystemFont there were cosmetic glitches displayed as well:

Under time pressure for a release, I implemented the workaround of replacing the NSTextField with an NSTextView. (I did this dynamically since it is not obvious how to create “bare” NSTextViews in Xcode’s Interface Builder.) Using an NSTextView I was able to get the data table to display as I had intended.

When writing up this bug (#29758498; Radar, Open Radar) I tried to create a simple test case that would illustrate the issue, but on my first try to recreate the problem from scratch, the issue didn’t appear. Puzzled, I copied the code and .xib file from my application into the test project, and was able to reproduce the issue.

By examining the text of the .xib files, I discovered that my newly created .xib file has a content view with wantsLayer=”YES”, and in this case the NSTextField works as intended under 10.12.2; but the .xib file from my application (which was created before Xcode 8 was released) did not have a layer set on the content view, and this did not work under 10.12.2 (although it had worked fine on 10.12.1 and earlier). Setting a layer on the application’s window’s content view (in the View Effects tab of the Assistant Editor in Xcode) was enough to fix the issue and make the table display as intended:

(Yes, bridge players, those point counts are bogus; my test program is generating random values to insert into the table.)

My wider questions are:

  1. What happened? We know there were a lot of graphic updates in 10.12.2, but it’s odd that the problem only occurs with the system font. I haven’t investigated whether the font file itself has changed.
  2. I can’t believe I’m the only person that’s run into this (although my usual googling produced no other hits). Is this really an uncommon case? Or is this a(nother) gap in Apple’s test suite?
  3. If Apple is expecting that the default case for content views is to have wantsLayer set, then it should certainly make this more widely known. I couldn’t find any references to this issue in the AppKit release notes.
2 Comments

VisualEffectPlayground in Swift

When searching for information on implementing vibrancy effects and NSVisualEffectView, developers often find references to the VisualEffectPlayground sample code presented by Apple at WWDC 2014. However, they soon quickly discover that Apple pulled the sample code from the Apple Developer site. Perhaps the application was thrown together for WWDC and didn’t meet the usual standard for Apple sample code; however, to date Apple has not seen fit to post any replacement. And so the search continues.

During my own search, I discovered that a Xamarin engineer named Oleg Demchenko had ported the sample code to Mono and posted it to the Xamarin samples site. In order to get a working sample application, I decided to port this code back to Swift and posted it to GitHub.

DISCLAIMER: I don’t know C# and I’m still learning Swift. Nevertheless, the resulting application appears to perform as expected (although I haven’t made an exhaustive test). I will certainly consider any pull requests.

1 Comment

Downloading Office 2011

What do you do when it turns out that your downloaded disk image of Microsoft Office 2011 for Mac is on the 3TB Seagate drive that failed last week, and you didn’t back it up because you thought all that was on it was archived TiVo recordings?

Turns Out™ TJ Luoma knows what to do. Thanks, TJ.

(Next time: recovering data from a 3TB Seagate drive…)

Update 2016-01-21: Also Turns Out™ that if you already have Office 2016 installed, you can log into your Office account and go to the Install page; there is a link that says “Install previous version”.  Clicking this will download a disk image file containing an Office 2011 installer.  (The creation date of this installer is November 20, 2015, and the contents appear to be version 14.5.9; the most recent update as of this writing is 14.6.0, so remember to run Check for Updates after installing.)

Comments closed

Updating the cover of the Swift iBook

Apple updated the cover of The Swift Programming Language to match the new book in the series, but deleting and redownloading the book within iBooks in OS X Mavericks didn’t update the cover — it continued to display the original cover.

The solution was to quit iBooks, delete the iBooks cache located at ~/Library/Containers/com.apple.iBooksX/Data/Library/Caches/com.apple.iBooksX, and restart iBooks.

You’re welcome, Internet.

5 Comments

Improved cwd restoration in tcsh

My previous post illustrating a technique for restoring the current working directory in Apple’s Terminal for tcsh users was discovered by Khoo Yit Phang, who suggested an improved version down in the comments. I’m reproducing it here for greater visibility:

if ("$?TERM_PROGRAM") then
  if ("$TERM_PROGRAM" == "Apple_Terminal") then
    alias cwdcmd '( set echo_style = both; echo -n "33]7;file://${host}${cwd:ags/ /%20/}a" )'
    cwdcmd
  endif
endif

Compared to my approach, it has two improvements: (1) by using cwdcmd (of which I was previously unaware) rather than precmd, it only runs when you actually change directories; and (2) by using a suitably configured echo, it avoids running an external command (printf is not built into tcsh, but is present in /usr/bin).

Thanks, Yit.

Update: Of course, with this technique you have to explicitly run the command once, to restore the working directory to the title bar for the first time when you start up. Fixed above.

Comments closed

Current working directory restoration in Mavericks Terminal with tcsh

In John Siracusa’s excellent review of OS X Mavericks, he (originally) mentioned that the Terminal application is able to restore the current working directory of open shells across launches.

However, this section has subsequently disappeared from the online version, perhaps for the reasons given below (update: see below). Try looking here for a cached version of the original; scroll down to page/slide number 94. Sorry, John. Please purchase the full review on the iBooks store or the Amazon Kindle store to support John’s work.

Of course I was excited to try this out as, in the course of my work as a software developer, I often have several shell windows open in specific directories. So I tried it, and it didn’t work. It turns out the built-in support supplied by Apple assumes that you’re using the bash shell, but as an old-timer I’m stuck on tcsh instead:

Well, that’s no good, I thought. So I looked in the supporting code’s implementation (/etc/bashrc), and figured out how to do the same thing in tcsh. Simply place the following in your .tcshrc file:

if ("$?TERM_PROGRAM") then
 if ("$TERM_PROGRAM" == "Apple_Terminal") then
  alias precmd 'printf "33]7;%sa" "file://$host$cwd:ags/ /%20/"'
 endif
endif

This uses the appropriate escape sequence to send the URL of the current working directory to the terminal before each command; Terminal detects this information and uses it to update the state of the window (including a proxy icon in the window’s title bar for the corresponding folder). It turns out that the key is doing it using precmd (tcsh’s equivalent of PROMPT_COMMAND), and not sending the sequence in the prompt string itself as one might think. (The outer if statement is necessary to avoid an error when remotely logging in, as with ssh. It has to be a separate statement because of the variable expansion rules in tcsh.)

I’ve notified John via Twitter, so perhaps he add restore this information back to his review. In any case, it’s documented here for future generations. Drop me a note below if you have any issues with it.

Update: It turns out John removed it because he discovered it was a feature in Mountain Lion as well, which had happened not to work on his machine:

If you listen to John’s podcasts, you’ll realize that makes sense: he wouldn’t let something not new in Mavericks stand in the Mavericks review. Regardless, I wasn’t aware of the feature before and it still wouldn’t have worked in tcsh, so this post is presumably still useful. (Note that I haven’t tried it on Mountain Lion, and I’ve already upgraded my working machines to Mavericks; I don’t know why this technique wouldn’t work on Mountain Lion, but use it at your own risk.)

Update 2: OK, so it turns out the feature was first implemented in Lion, and other people have already figured out how to port it to other shells; see here for an implementation in zsh, for example. How did I manage to not learn about this for the last two years? Oh, well…

5 Comments