Archive for the 'Mac OS X' Category

Apple Bug Friday! 52

Friday, March 23rd, 2007

This bug is Apple applications use a modal window for print progress. It was filed on 2007-03-09 at 14:06 PST.

(more…)

How to make the HP Photosmart M425 work on a Mac

Monday, March 12th, 2007
  1. Get out the HP drivers CD.
  2. Put it in one of these.
  3. Push the button.

Silly me, trying to use a device with the Mac drivers that come with the device. Turns out it works just fine with the built-in Mac OS X drivers, either via PTP (whatever that is), or as a mass-storage device. In fact, Image Capture works the same either way.

With the HP drivers, a program called “HPCamera_PTP” would crash whenever I plugged in the camera, whether I did this in Image Capture or iPhoto. I found that switching the camera to mass-storage mode (“Disk Drive” in the USB Configuration menu) worked around that problem nicely, and Image Capture (and iPhoto) even work transparently in this mode.

Later, I was tinkering with Image Capture in some way (I forget why) and noticed that it has its own PTP driver. This gave me an idea, and having long ago uninstalled the HP uselessware, I switched the camera back to PTP mode (“Digital Camera” in the USB Configuration menu) and plugged it back in. Huzzah! It worked exactly as it did in mass-storage mode.

Kudos to Apple for making it do the Right Thing either way. Antikudos to HP for making non-functional drivers.

I also got a new scanner yesterday, a CanoScan LiDE 600F. Unfortunately, it doesn’t work without drivers. Fortunately, its drivers work. (Both devices let me use Image Capture without touching any of the apps that come with them, which I consider mandatory given the nearly-consistent asstasticity of the UIs of such apps in general.)

What’s the resolution of your screen?

Sunday, February 4th, 2007

A few weeks ago, I installed Adobe Reader to view a particular PDF, and noticed something interesting in its Preferences:

Its Resolution setting is set by default to “System setting: 98 dpi”.

“Wow”, I thought, “I wonder how it knows that.” So I went looking through the Quartz Display Services documentation, and found it.

The function is CGDisplayScreenSize. It returns a struct CGSize containing the number of millimeters in each dimension of the physical size of the screen. Convert to inches and divide the number of pixels by it, and you’ve got DPI.

Not all displays support EDID (which is what the docs for CGDisplayScreenSize say it uses); if yours doesn’t, CGDisplayScreenSize will return CGSizeZero. Watch for this; failure to account for this possibility will lead to division-by-zero errors.

Here’s an app to demonstrate this technique:

ShowAllResolutions' main window: “Resolution from Quartz Display Services: 98.52×96.33 dpi. Resolution from NSScreen: 72 dpi.”

ShowAllResolutions will show one of these windows on each display on your computer, and it should update if your display configuration changes (e.g. you change resolution or plug/unplug a display). If CGDisplayScreenSize comes back with CGZeroSize, ShowAllResolutions will state its resolution as 0 dpi both ways.

The practical usage of this is for things like Adobe Reader and Preview (note: Preview doesn’t do this), and their photographic equivalents. If you’re writing an image editor of any kind, you should consider using the screen resolution to correct the magnification factor so that a 8.5×11″ image takes up exactly 8.5″ across (and 11″ down, if possible).

“Ah,”, you say, “but what about Resolution Independence?”.

The theory of Resolution Independence is that in some future version of Mac OS X (possibly Leopard), the OS will automatically set the UI scale factor so that the interface objects will be some fixed number of (meters|inches) in size, rather than some absolute number of pixels. So in my case, it would set the UI scale factor to roughly 98/72, or about 1+⅓.

This is a great idea, but it screws up the Adobe Reader theory of automatic magnification. With its setting that asks you what resolution your display is, it inherently assumes that your virtual display is 72 dpi—that is, that your UI is not scaled. Multiplying by 98/72 is not appropriate when the entire UI has already been multiplied by this same factor; you would essentially be doing the multiplication twice (the OS does it once, and then you do it again).

The solution to that is in the bottom half of that window. While I was working on ShowAllResolutions, I noticed that NSScreen also has a means to ascertain the screen’s resolution: [[[myScreen deviceDescription] objectForKey:NSDeviceResolution] sizeValue]. It’s not the same as the Quartz Display Services function, as you can see; it seemingly returns { 72, 72 } constantly.

Except it doesn’t.

In fact, the size that it returns is premultiplied by the UI scale factor; if you set your scale factor to 2 in Quartz Debug and launch ShowAllResolutions, you’ll see that NSScreen now returns { 144, 144 }.

The Resolution-Independent version of Mac OS X will probably use CGDisplayScreenSize to set the scale factor automatically, so that on that version of Mac OS X, NSScreen will probably return { 98.52, 98.52 }, { 96.33, 96.33 }, or { 98.52, 96.33 } for me. At that point, dividing the resolution you derived from CGDisplayScreenSize by the resolution you got from NSScreen will be a no-op, and the PDF view will not be doubly-magnified after all. It will be magnified by 133+⅓% by the UI scale factor, and then magnified again by 100% (CGDisplayScreenSize divided by NSDeviceResolution) by the app.

Obviously, that’s assuming that the app actually uses NSScreen to get the virtual resolution, or corrects for HIGetScaleFactor() itself. Adobe Reader doesn’t do that, unfortunately, so it suffers the double-multiplication problem.

So, the summary:

  • To scale your drawing so that its size matches up to real-world measurements, scale by NSDeviceResolution divided by { 72.0f, 72.0f }. For example, in my case, you would scale by { 98.52, 96.33 } / { 72.0, 72.0 } (that is, the x-axis by 98.52/72 and the y-axis by 96.33/72). The correct screen to ask for its resolution is generally [[self window] screen] (where self is a kind of NSView).
  • You do not need to worry about HIGetScaleFactor most of the time. It is only useful for things like -[NSStatusBar thickness], which return a number of pixels rather than points (which is inconvenient in, say, your status item’s content view).

How I learned Dvorak

Saturday, February 3rd, 2007
  1. Print out all the letters and some punctuation onto sticker paper. For a US keyboard, you’ll need the alphabet except a and m, and all of “-=[];’/,.” I’ve forgotten the font I used (it was years ago that I did this), but I can offer you this: On my keyboard (a Macally iKey), the letters are 4 mm tall. [UPDATE 2008-11-29: On my Apple Extended Keyboard II, the letters are in Univers, approximately 10 point.]
  2. Cut out the characters and affix each one to the matching key in the Dvorak position. For example, the ‘p’ goes on the QWERTY ‘r’ key (top row, fourth in from tab). Using labels rather than rearranging your keys allows you to easily switch back to QWERTY if you should need to for something.
  3. Hunt-and-peck with this arrangement. Do as much typing as you can arrange for yourself. Pay attention to the letter arrangement, which is not accidental—the vowels are all together on the left and many common digraphs (e.g. tr, nt, ?s, th) are on the right.
  4. When not at your computer, air-type in the Dvorak positions. This gets you used to the finger movements. Muscle memory is your friend. Anytime you daydream, or speak, or hear speech, narrate it in text on a keyboard of air. You don’t need your arms in position for this; at your sides/in your pockets will work just fine. It’s your hands that you’re training.
  5. At the end of about two weeks, the stickers will fall off of the keys, and you will not complain because you have ceased to need them.

It wasn’t much longer before I had matched my old QWERTY speed, and I’ve since surpassed it—I type around 100 WPM. (Curious as to your own WPM? Try this free typing test.) I’m rusty with QWERTY now, but I can still type it if I need to.

SpotlightFS quickie

Wednesday, January 24th, 2007

Just to save you the time of trying this yourself, the answer is yes, you can use arbitrary queries with SpotlightFS.

mkdir 'kMDItemTitle = "A Day In The Life"'             %/Volumes/SpotlightFS(0)
___
ls 'kMDItemTitle = "A Day In The Life"'                %/Volumes/SpotlightFS(0)
:Users:prh:Music:iTunes:iTunes Music:The Beatles:Love:23 A Day In The Life.m4a@
:Users:prh:Music:iTunes:iTunes Music:The Beatles:Sgt. Pepper's Lonely Hearts Club Band:13 A Day In The Life.m4a@
:Users:prh:Music:iTunes:iTunes Music:The Beatles:The Beatles 1967–1970:1-06 A Day In The Life.m4a@
Icon?*
___
mkdir 'kMDItemTitle = "A Day In The Life" && kMDItemAlbum = "Sgt.*"'
___
ls 'kMDItemTitle = "A Day In The Life" && kMDItemAlbum = "Sgt.*"'   
:Users:prh:Music:iTunes:iTunes Music:The Beatles:Sgt. Pepper's Lonely Hearts Club Band:13 A Day In The Life.m4a@
Icon?*

I also would suggest defining a shell function that does the mkdir-ls-rmdir dance in one step.

How the Preferences have grown

Wednesday, January 10th, 2007

BBEdit Lite 6.1.2 vs TextWrangler 2.2:

BBEdit Lite's Preferences window is 461 by 348 points. TextWrangler's Preferences window is 750 by 572 points.

Screencast codec showdown

Friday, December 8th, 2006

So I’m looking at making some screencasts in iShowU. I noticed that, thanks to QuickTime, it supports rather a lot of codecs:

iShowU's codecs pop-up menu, showing 29 different codecs of various suitability.

Dizzying, isn’t it?

So I asked the Goog about some of the codecs, and also more generically about screencast codecs. H.264 is a popular choice, but I found no comparison to other codecs nor any discussion of what any of the codecs is particularly good at.

I also had a small amount of previous experience with the difference between codecs. I’ve watched two of rentzsch‘s screencasts: “Introduction to Core Data” and “Embedded Cocoa Frameworks”. The former is 1024×768 using H.264; the latter is 800×600 using Sorenson 3. “Introduction to Core Data” looked flawless; “Embedded Cocoa Frameworks”, OTOH, had noticeable artifacts. I wondered at first what the difference was, and after I found out, whether there wasn’t a better codec with which to implement screencasts.

Part of the problem is that there really isn’t a codec that’s been well-optimized for screencasting. Video codecs have historically been optimized for, well, video — that is, video shot with a camera. Screen images usually don’t change much except to follow mouse movements; a compressor specifically optimized for recording the screen should make a big difference in screencast file sizes. Are you listening, Apple? (Or Ambrosia?)

Anyway. In order to find the perfect (so far) screencast codec, I recorded a brief screencast using iShowU in demo mode using the None (no-compression) codec, and used QTAmateur by Michael Ash to export it to all the other codecs.

The results? Well, you’ll just have to read the screencast codec showdown for yourself. ☺

The best developer tool since Interface Builder

Tuesday, October 31st, 2006

Yesterday, wootest created an app called ThisService. I’ll put this disclaimer right up front: He is a reader of this blog, and he allowed me to test a prerelease version of ThisService. But neither of these facts affects the opinion that I’m about to state.

ThisService is the greatest developer tool since Interface Builder.

UNIX has an interface paradigm called the “filter”. This is an application that reads zero or more input from its standard input special-file, operates on or with the data in some way, and writes zero or more output to its standard output special-file. This simple design is amazingly versatile, and highly conducive to simple but effective IPC.

NeXT took the same concept and extended it to the GUI with what it called System Services. Some of you may have seen these; they live on in OS X, more or less unchanged as far as I’ve seen. And their operation is pretty much the same: take some input (or not), do something to or with it, and emit some output (or not).

So John Gruber, according to himself, had the idea for an application that takes a filter program and makes a system service from it, and put this idea to wootest. Didn’t take him long, apparently; I beta-tested it last night, and the app is now at 1.0.

ThisService 1.0 main window.

Pretty simple. You give ThisService the filter’s name, location, behavior, and an optional hotkey, and it will create a system service application for you.

Services are very versatile. Consider the Objective-C service, or the Copy File Path service, or CalcService, or Tidy Service. Quite a range of functions, no? But Apple does not make a very big deal of the Services system’s existence, and so the feature sits unused by most users. When’s the last time you visited the Services menu?

And yes, this is despite the fact that many Apple applications — some of them big-name, some of them more quiet necessities — provide services. In fact, core OS X apps provide most of the services on most people’s systems. This, of course, is because on the whole, nobody else knows about Services.

I think that ThisService will change all that. The fact you can now write an OS X service in Python/Perl/awk/C/$FAD_LANGUAGE in exactly the same way that you would write a UNIX filter makes creating services now trivial. So I think that we’ll see plenty of applications in the future built with ThisService, perhaps with a badge somewhere on the webpage proclaiming that fact, with instructions like this:

This application is an OS X “system service”.

  • To install it, simply drag it to your Home/Library/Services folder (first creating that folder if necessary). It will then be available in most applications.
  • To use it, choose “service-name” from the Services menu in the Application menu (the menu just to the right of the Apple menu).
  • To remove it, take it out of the Library/Services folder, e.g. to the Trash.

(Feel free to copy the above instructions, even if you don’t use ThisService to create your service.)

The first wave or two of these new services will be geek-oriented. Programmers will take their existing stashes of filters that they’ve created (such as mine) and make services out of them and put them on their websites. Thus, the first influx of service users will be geeks (including, but not limited to, other programmers).

But then I predict a larger resurgence in services. People will start making new services from other filters that have broader utility, like sort. There may even be a new attraction to making services directly, either from scratch, or from a UNIX filter but with a GUI on top to specify options (i.e. not using ThisService). And then I think the larger, non-technical userbase will start using services.

It will be a great day.

UNIX commands that are also questions

Friday, September 8th, 2006

Just because I find sets like this amusing.

what
“show what versions of object modules were used to construct a file”
whence
“For each name, indicate how it would be interpreted if used as a command name.”
where
“Equivalent to whence -ca.” (-c: “Print the results in a csh-like format.” -a: “Do a search for all occurrences of name throughout the command path. Normally only the first occurrence is printed.”)
which
“Equivalent to whence -c.”
who
“show who is logged on”
who
“show who is logged on”
wtf
Defines acronyms.

Missing, of course, are why, when, whom, and wherefore. Somebody please write these utilities. ☺

UPDATE 2006-11-02: wootest pointed out that “why” was missing from the missing list, and this caused me to remember that “wtf” was missing from the main list. Both omissions are now fixed. Thanks!

A Terminal quickie

Thursday, August 17th, 2006

I’ve been reading Jeff Atwood’s Coding Horror blog (love the favicon, BTW). I got to the post where he talks about the Consolas font as compared to Lucida Console, and shows it with and without ClearType (anti-aliasing). You can download Consolas (and a few other fonts) from this post on Jeff Milner’s blog.

Looks good, so I wanted to try it in Terminal (even though I use xterm — yes, I’m like that). Looks good in Terminal, too, but I was reminded of a problem with Terminal and box-drawing characters:

Terminal, showing a box drawn by a shell script. Each box-drawing character (that is, line segment or corner character) is twice as wide as it needs to be, which is throwing off spacing and causing each of the lines with a box-drawing character on them to overrun the width of the terminal.

That box is supposed to fit within my screen and be centered in its horizon. Not working so well.

The culprit is the “Enable wide glyphs for Japanese/Chinese/etc.” checkbox on the Display pane of the Terminal Inspector. Apparently box-drawing characters count as “etc.”. Turn that off, and sanity is restored:

Terminal, showing the same box drawn by the same shell script, with “Enable wide glyphs for Japanese/Chinese/etc.” turned off. Each box-drawing character is now the same width each of the other (non-box-drawing) characters.

Don’t forget to Save Default Settings after you frob the checkbox. Unless you do, the new value will not be applied to future Terminals.

Technorati tags: .

Whoa, what happened to Monaco 9?

Thursday, July 6th, 2006

A C source file, viewed in Monaco 9, in SimpleText in Mac OS 9.2.1.
The same C source file, viewed in Monaco 9, in TextEdit in Mac OS X 10.4.6.

I think they got rid of the screen font. It’s just using the outline font now.

Wow. Just… wow.

Technorati tags: , .

Apple bug Friday! 44

Friday, June 30th, 2006

This bug is PackageMaker’s keyboard shortcuts are not consistent with Xcode’s. It was filed on 2006-05-19 at 02:28 PDT.

The list in the Notes section is adapted from another blog post of mine, Know your Xcode.


Summary:

PackageMaker’s keyboard shortcuts for Build, Build Log, Run, and Run Log do not match up with Xcode’s shortcuts for the same commands.

Steps to Reproduce:

  1. Press ⇧⌘B.

Expected Results:

The Build Log appears.

Actual Results:

*Beep*

Regression:

None known.

Notes:

Xcode has a simple and elegant system for its keyboard shortcuts:

  • ⌘_ builds, then performs the action.
  • ⌘⌥_ performs the action without building. (Exception: Build’s keyboard shortcut is ⌘B, presumably because it is impossible to build without building.)
  • ⇧⌘_ shows the log for the action.

PackageMaker should adopt the same schema, both for its elegance and for uniformity with Xcode.


Technorati tags: ,

Call to action

Thursday, June 29th, 2006

I want to see Mac OS X Tiger (or Leopard) running on a NeXT Cube. :)

And NeXTStations only count for half points. They’re too modern. I want to see it on a NeXT Cube, grayscale and all.

If you make it happen, or find somebody who has made it happen, please post a link in the comments.

Technorati tags: , NeXT.

Report-an-Apple-bug Friday! 43

Friday, June 2nd, 2006

This bug is CrashReporter dialog has “Close” button. It was filed on 2006-06-02 at 03:17 PDT.


Summary:

The “unexpectedly quit” dialog has a “Close” button.

Steps to Reproduce:

  1. Crash an application.

Expected Results:

A dialog box comes up, saying that the application has unexpectedly quit, showing the backtrace, and offering me the option to either “Report” the crash or one of:

  • Quit [the application]
  • Cancel [reporting]
  • Don’t Report

Actual Results:

A dialog box comes up, saying that the application has unexpectedly quit, showing the backtrace, and offering me the option to either “Report” the crash or “Close” something.

Regression:

None known.

Notes:

It is not clear what is being closed. I think the immediate guess is the application; only on further reflection does one realize that if the application has already quit, it must not be available to be “closed”. It could refer to the window, but isn’t that what the red widget is for? But there is no red widget, because this is a dialog box.

The button’s title should be changed, to one of the three names listed in Expected Results. Of those, my favorite is “Don’t Report”.

The CrashReporter dialog box, with its “Close” button.


Technorati tags: ,

How to create a RAM disk

Tuesday, May 9th, 2006

Added 2007-09-29: This is the hard way. The easy way is my free app Make RAM Disk. It does the same process shown here, but with a lot less effort from you.

I just posted to this lisppaste with a punt solution. Since this solution really has nothing to do directly with the problem stated, I thought I’d share it with you as well, with HTMLization and some editing from the original.

  1. hdiutil attach -nomount ram://num_sectors (sector = 512 bytes = 0.5 K)

    This outputs a device path (/dev/foo) on stdout.

  2. newfs_hfs -v volume_name device_path

    Formats the RAM disk as HFS+. See the manpage for other options.

    [Added 2007-09-23] If you want a case-sensitive file-system (HFS+ being case-insensitive by default), add the -s flag before the device_path.

    [Added 2007-10-14] If you’d rather not use HFS+, then you can use newfs_msdos to get FAT12, FAT16, or FAT32 (you choose which with the -F option), or newfs to get UFS.

  3. diskutil mount device_path

    The RAM disk will be mounted at /Volumes/volume_name.

You could also do something involving mount(8) instead of diskutil if you wanted to mount it inside NSTemporaryDirectory(). Remember to unmount it (hdiutil detach device_path, or the Eject command in the Finder or Dock) when you’re done.

UPDATE 2007-08-07: Changed from hdid to hdiutil attach, since hdid is deprecated and hdiutil works just as well.

UPDATE 2007-09-29: Added link to Make RAM Disk.

UPDATE 2007-10-14: Added references to other commands in the newfs family (specifically, newfs_msdos and newfs).

Report-an-Apple-bug Friday! 38

Friday, April 28th, 2006

This bug is Can’t drag text into a text input in a form. It was filed on 2006-04-28 at 01:07 PDT.


Summary:

Inputs of type “text” do not register themselves as drop targets.

Steps to Reproduce:

  1. Select some text. I used some text in Adium’s inputline, and in a textarea in Safari, and on the page in Safari.
  2. Drag it into an input of type “text” in a form on a page in Safari.

Expected Results:

The input accepts the drop.

Actual Results:

The input fails the drop.

Regression:

None known.

Notes:

Dragging to a textarea works.


At 05:14, I uploaded a test case.


Technorati tags: ,

Report-an-Apple-bug Friday! 37

Friday, April 28th, 2006

This bug is Volume MenuExtra is not accessible. It was filed on 2006-04-28 at 00:54 PDT.


Summary:

The slider in the Volume MenuExtra is not usable by Accessibility applications.

Steps to Reproduce:

  1. Launch the Accessibility Inspector.
  2. Click on the Volume MenuExtra.
  3. Point to the slider.

Expected Results:

Accessibility Inspector describes a slider.

Actual Results:

Attributes:

AXRole: “AXUnknown”

AXRoleDescription: “unknown”

AXChildren: “

AXParent: “

AXPosition: “x=987 y=22”

AXSize: “w=29 h=116”

AXEnabled: “true”

Regression:

None known. The Volume MenuExtra from Panther (10.3.9) has the same problem.

Notes:

None.


Technorati tags: ,

Report-an-Apple-bug Friday! 32

Friday, April 21st, 2006

This bug is Can’t reorder login items in Accounts preference pane. It was filed on 2006-04-21 at 20:53 PDT.


Summary:

The Accounts preference pane does not allow you to drag and drop login items into different orders.

Steps to Reproduce:

  1. Drag a login item to a different position.

Expected Results:

The login item is moved.

Actual Results:

The prefpane does a multiple selection.

Regression:

None known.

Notes:

Probably results from rdar://4523642.

Workaround:

Edit loginwindow.plist directly.


Technorati tags: , .

Report-an-Apple-bug Friday! 31

Friday, April 21st, 2006

This bug is System Events does not allow insertion of Login Items. It was filed on 2006-04-21 at 20:53 PDT.


Summary:

No supported way exists to insert a login item at a specific index, rather than just the end.

Steps to Reproduce:

  1. Run the following AppleScript script: tell application "System Events" to make new login item at login item 1 with properties {name:"Foo", path:"X:Y:Z:Foo", kind:"application", hidden:false}

Expected Results:

The login item is inserted at the start of the list.

Actual Results:

The login item is inserted at the end of the list.

Regression:

None known.

Notes:

None.

Workaround:

Edit loginwindow.plist directly.


Technorati tags: , .

Making Spotlight work for you

Saturday, April 8th, 2006

For a long time now, I’ve kept Spotlight disabled because it constantly cranked away at my hard drive. I couldn’t figure out why that was, until recently, when I had an epiphany:

  • Spotlight updates its index when a file is updated.
  • If Spotlight is updating constantly, one or more files must be getting constantly updated.

What sort of file gets constantly updated?

That’s right. A log file.

So I added the folder with my IRC logs to the blacklist in the “Privacy” tab in Spotlight preferences, et voila, the constant indexing stopped.

Problem solved.

Technorati tags: Spotlight.