Archive for the ‘OS X’ Category

Bouncing AirDrop contents to my desktop

I never use my Downloads folder. It’s a fusion drive, so it’s precious, fast, and expensive. I don’t need a thousand downloaded copies of Xcode and firmware updates littering its limited space. Instead, I point all my browsers and other apps to download to my secondary data disk.

Screen Shot 2016-06-27 at 12.57.18 PM

And before you ask, I use numerical and alphabetic prefixes so everything shows up in the right place and the right order for quick reference and single-letter typing access. Whatever data I can offload from my main drive, I do offload:

Screen Shot 2016-06-27 at 12.59.42 PM

However, when it comes to airdropping, it’s generally true that whatever I’m sending back and forth is of immediate interest. In such case, I don’t want it heading into my Downloads folder. I want it on my desktop as soon as it lands. As  I’m updating my Playgrounds Book right now, I’m doing a lot more airdropping than I normally would.

I’m not a big user of smart folders and Automator actions. I have a smallish bunch that I occasionally use. Still, they have their place and today was a perfect occasion to bring a new one into the mix.

I just had had it with the Downloads folder and decided to build a bouncer that would automatically throw any item added to ~/Downloads up to the desktop. I thought I’d share how to do this.

Step 1. Create a new Folder Action

Screen Shot 2016-06-27 at 1.03.48 PM

Step 2. Choose the Downloads folder.

Screen Shot 2016-06-27 at 1.05.50 PM

Step 3. Drag “Move Finder Items” onto “Drag actions or files here to build your workflow”

Screen Shot 2016-06-27 at 1.06.37 PM

Screen Shot 2016-06-27 at 1.06.48 PM

This creates the following action, with Desktop selected by default. (If it’s not, choose Desktop for the destination.)

Screen Shot 2016-06-27 at 1.07.24 PM

Step 4. Then save:

Screen Shot 2016-06-27 at 1.09.12 PM

Your new automator action is stored in ~/Library/Workflows/Applications/Folder\ Actions:

Screen Shot 2016-06-27 at 1.11.43 PM

Step 5. Test. Drop a file into Downloads and confirm that it moves to the desktop. You should now be ready to airdrop to your desktop.

Note: I’m sure there’s a better way to do this, but I actually wrote an app that quickly opens AirDrop windows on the Mac side of things. I found an appropriate AppleScript online, compiled it to an app, and use Spotlight to launch it. Very handy when I’m more focused on iOS than OS X at the moment.

Pinning tabs in Safari

Because sometimes people forget: Right-click the tab and choose Pin Tab from the pop-up. To remove a pinned tab, right-click again and either un-pin or close it.

Pinned tabs appear in all new tabbed browser windows as well.

Screen Shot 2016-04-13 at 4.04.55 PM Screen Shot 2016-04-13 at 4.05.02 PM

Weekend Posts

OS X Maps hint of the day

Want to grab the latest Maps data and don’t want to wait for updates? I’ve heard of a quick and easy solution, which is to delete ~/Library/Caches/GeoServices. This forces a cache flush and updates all your maps.

I noticed this might be especially handy today for those of you who use public transit in DC, Philly, Mexico City or Chicago.  Happy traveling all.

CSS and Attributed Strings

Can you initialize an attributed string with CSS-populated HTML? This question popped up in #iphonedev. The answer is: kind of. HTML initialization is meant for lightweight use, not for full page layout. But yes, you can.

Screen Shot 2015-08-24 at 2.55.14 PM

This question in particular had to do with whether you could customize  list bullets:

Screen Shot 2015-08-24 at 3.05.37 PM

As far as I know, you cannot use externally sourced images but if you worked hard enough (and I’m not willing to do that), there are always attributed strings image attachments.

The upshot of all this is 1: I touched CSS. 2: I’m busy trying to figure out error naming. and 3: I figured that if it’s really important you’ll either use a web view or work out a post-hoc way to insert attachments that I’m not willing to spend any time on here but someone will point me to them if I throw out a post.

There you go.


enum AttributedStringError : ErrorType {case Unconstructable}
func stringWithHTMLString(var string : String) throws -> NSAttributedString {
    string = string.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
    if !string.hasPrefix("<html>") {string = "<html>" + string}
    if !string.hasSuffix("</html>") {string = string + "</html>"}
    guard let htmlData = string.dataUsingEncoding(NSUTF8StringEncoding) else {
        throw AttributedStringError.Unconstructable}
    var attributes : NSDictionary = [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType]
    let options = [String : AnyObject]()
    let aptr = AutoreleasingUnsafeMutablePointer<NSDictionary?>(&attributes)
    return try NSAttributedString(data: htmlData, options: options, documentAttributes: aptr)


As I’m handing over my 2010 MacBook Air to eldest child, it occurs to me that computing today is very different from 2010.

The MacBook did an okay job in its life. It hosted many OS’s, mostly betas, and was a go-to for kids homework, but it really stank at the one job that differentiated it from my iPad, which is to run Xcode and navigate docs.

Xcode doesn’t want to be on a teeny tiny screen with a crappy keyboard. It wants full glorious mechanical travel and many large monitors.

No matter how many times I promised myself that this time, I’d figure out how to do some light development on the damned thing, I ended up using it as a poorly designed iPad — email, browsing, books, media.

Its greatest utility was booting up a half dozen operating systems to test backward compatibility as it sat 2 feet away from my primary dev machine.

I don’t know what it is about laptops and me. For whatever reason, I can’t seem to get along with decaffeinated OS X. I can iPad, I can desktop, but I just can’t seem to laptop.

Perhaps I’m just deluding myself that there people out there who can actually get real work done on these things. What I can’t figure out is how.

What is the critical equipment line over which you can actually do development? Does it involve bringing along a 24″ monitor and a loud clicky keyboard to the coffee shop, or on a plane?

I’m back to lurking at the online store, trying to figure out if it’s even worth picking up a replacement at this point. What I really want is a portable ultra-light iMac/iPad hybrid, complete with handle on top and kickstand, and that’s just not going to ever happen.

So what do you suggest I look into? Will Retina make all the difference for my bad eyes? Or should I hold out for the mythical hockey-puck Mac or the iPadMac? What’s your advice? And how do you get that work done on yours?


Blast from the past: All I want for WWDC is…nothing


Logo has been fixed by  Radek Pietruszewski ‏@radexp        


From February 2014: original post

February may seem early to you to be strategizing about Apple WWDC announcements. For tech writers, it’s crunch time. To plan books, posts, and other coverage, you try to anticipate how big a change is coming up and what areas will be affected.

For example, Victor was asking me the other day what I’d like to see in the next installments of iOS and OS X. My answer is the same as it’s been for years: “Bug fixes and security enhancements.” I’m a bit over the yearly update cycle.

Read On…

Swift: Today’s Wow moment. Adding menus to playgrounds

I finally figured out how to get a nib/xib loaded into a playground and use it to power an app menu. It’s ridiculous how long this took and how simple the solution turned out to be.

Each playground, regardless of whether you’re building iOS or OS X code, runs as a tiny independent app on your computer. You can find that executable, and the app it is running in by peeking at NSBundle.mainBundle().executablePath.

Playground apps are tiny.  OS X versions consist of a minimal bundle with a stripped-down Info.plist, a Resources folder, and a MacOS executable.

You can throw a xib file into your Resources, but the playground cannot read it or run it because it’s not in compiled form. Today, I (finallly!) thought of using ibtool to pre-compile my MainMenu.xib file into nib and then load that. When you install Xcode’s command line tools, ibtool gets added to /usr/bin. So all you need to do to compile your nib is issue the following command:

ibtool --compile MainMenu.nib MainMenu.xib

Throw that resulting nib into your playground’s resources folder and you’re ready to load it up.

The trickiest bit was trying to get all the unsafe autoreleasing mutable pointer stuff working. Swift is like a perfect haiku. It all looks simple and obvious when you’ve finished writing it but getting it debugged is a pain. The answer, by the way is this, which hopefully people will be able to google up without having to go through an hour or two of tweakage:

var array = NSArray()
var outputValue = AutoreleasingUnsafeMutablePointer<NSArray?>(&array)
NSBundle.mainBundle().loadNibNamed("MainMenu", owner: nil, topLevelObjects: outputValue)

A few further points:

I built a simple compile command line shell script so I don’t have to remember the order of the files or the arguments for ibtool. You can see it in the video in the Resources folder.

Add your xib source into your Resources as well as your compiled nib. You can then edit the xib using Xcode editors directly from the playground workspace. You still have to compile outside it. I keep a terminal window open to simplify the process.

Every now and then Xcode automatically moves things around, so use a full path in the terminal. Then use the terminal’s history to re-issue the same command as needed:

cd /Users/ericasadun/Desktop/Playgrounds/X\ -\ Playgrounds/OSX\ Menu.playground/Resources ; ./compile

Don’t compile when your nib is in use.  Comment out the XCP indefinite execution line and the loadNibNamed line, and then compile in place from the command line.

You can’t much in the way of binding in your xib but you can design stuff there and then add the targets and behavior in the playground.

Utility: Finding untagged files and folders at the command-line

How do you find untagged items? This question popped up in #macdev for someone working on a Dropbox-based backup system of all things. So how do you find just those items in a folder that are untagged? Use mdfind:

mdfind -onlyin . "kMDItemUserTags != '*'" | open -f

If you switch that inequality to ==, you’ll retrieve all tagged items instead.

Folderol makes extensive use of tags. You can search for specific tags using names within the single parens, e.g. to find all the Green system tags:

mdfind -onlyin . "kMDItemUserTags == 'Green'" | open -f

The built in tag names are Red, Orange, Yellow, Green, Blue, Purple, and Gray, but you can assign any tag name you like in Get Info or by using the tag field in Folderol. Then, with a liberal use of asterisks, you can search for, for example, items with tags that contain the word Neon or neon (the [c] means case insensitive).

mdfind -onlyin . "kMDItemUserTags ==[c] '*Neon*'" | open -f

Or tags that start with Neon

mdfind -onlyin . "kMDItemUserTags == 'Neon*'" | open -f

Or end with Neon

mdfind -onlyin . "kMDItemUserTags == 'Neon*'" | open -f

In addition to the [c], you can use [d] (or [cd]) to add diacritical insensitivity, so a search for “café” would also match “cafe”.

To find all Folderol-set custom color tags, search for “(*)”. This excludes standard system tags, although if you’ve tagged with both a custom tag and a system one, the file or folder will appear in the results.

mdfind -onlyin . "kMDItemUserTags == '*(\*)*'" | open -f

Unreadable PDF. Who knew? (An ode to @ecammtweets)

Screen Shot 2015-02-23 at 11.57.34 AM

My son’s school recently emailed me some forms. I was about to acknowledge their receipt when I discovered I could not read them. Instead of seeing the forms they’d sent, I could only view some message about my PDF viewer (Mail and Finder in this case) not being able to display the file.

“If this message is not eventually replaced by the proper contents of the document, your PDF viewer may not be able to display this kind of document.” It then instructed me to upgrade to the latest version of Adobe Reader, a suggestion that in context seemed slightly hilarious as I wasn’t using Adobe Reader in any fashion at the time.

It turns out that some Adobe PDFs have this marvelous property: They can only be read by Adobe software. It took a bit of googlage until I finally found a site that explained the situation. No Adobe, no read.

Fortunately, I have a version of Adobe CS 4 still installed on my Mac, although it’s held together these days by spit and bandaids. Hello 2008. I was able to get Acrobat Pro running and sure enough, I could open the doc in the app and it was readable.

Naturally, I tried to use OS X’s built-in PDF rendering to print to file. Bzzzzzt. That (of course) was not allowed.

Screen Shot 2015-02-23 at 12.03.17 PM

Thank goodness for Ecamm. Instead of printing to “file”, I used my copy of their Printopia extension ($19.99) to print to my Mac instead. Instantly my unreadable PDF file transformed to a readable one. I simply pulled the rendered PDF out of my Documents/Printopia folder and it was ready to use. Printopia saved the day. Thanks, Ecamm. And hopefully this write-up will be googlable for anyone who encounters the same kind of problem with a PDF file that cannot be read in OS X mail.

As a final note, I’m told that you might be able to contact the person who prepared the PDF and ask them to switch the limitation off and resave. This would allow the document to be opened in any PDF viewer. When dealing with low-level administrative staff employed in the public school system, however, you might just want to know about alternative approaches so you can go-it on your own.