Stupid Mac Tricks

Max your Mac with these handy tips!

Send Google Reader Items to OmniFocus

Google Reader has a nifty “Send To…” feature that lets you push reader items to other services — such as social networks, Instapaper, and so forth.

I have recently set up a Send To service that will send your Google Reader articles to OmniFocus, provided you’re using version 1.8 or later. (Currently in beta, download it here) (Props and full credit goes to Gokubi for setting this up for version 1.7 — I just polished it up a bit and used the native URI handler in OF 1.8)

Setup is pretty simple. In Google Reader, go to your Reader Settings (upper right corner), and click on the “Send To” tab. Then you just have to add a new service, and use the following settings:

Name: OmniFocus

Send to URL: http://omnifocus.nik.me?name=${title}&note=From+${source}%3A+${short-url}

Icon URL: http://omnifocus.nik.me/OmniFocus-16.png

Then just go back to Google Reader, and choose Send To on an article (or type Shift + T), and select OmniFocus.

Again, this only works with OmniFocus 1.8, which is in beta right now. If you want the same functionality without having to switch to a potentially untrustworthy version of OF, you can use Gokubi’s original setup, which leverages my URI handler for OF 1.7 and earlier.

AppleScript tricks: What to Do When the Frontmost Window Isn't Frontmost

The Problem: Scripts often target the current document window of an application. This is usually easily handled with something like…

Tell application "Finder" to get window 1

The problem with this approach is that it returns a useless window if the wrong kind of window is in front. In the Finder, this will often be a Get Info window, folder options window, or preferences. Some applications have special classes of windows to make this easier, but many do not. To find the frontmost window of these applications, you need to do this manually.

To make this work, you need to loop through your windows until you find one of the right type. You could do this by the name of the window (e.g. find Finder windows whose names don’t contain “Finder Preferences”), but that requires you to catalog the names of every non-standard window, and can cause problems if, for example, you have a folder named “Finder Preferences.”

A better approach is to identify a property that only the right kind of windows contain. So, for Finder windows, you can look for the folder of the window, as in…

Tell application "Finder"
        set theFolder to (path to desktop folder as alias)
        repeat with i from 0 to (count of windows)
                try
                        get folder of window i
                        set theFolder to result as alias
                        exit repeat
                end try
        end repeat
end tell

In this code, the “try” handler gracefully handles windows without the “folder” property. Likewise, by setting theFolder to the Desktop to begin with, it also handles the situation where there are no open windows.

Using this technique, the following script will open the current Finder window in a new tab in the frontmost Terminal window. If there isn’t a terminal window available, it opens a new window. The code gets pretty involved for the Terminal (including having to go to UI scripting to make a new tab), but it avoids the pitfalls of multiple open windows in each application, not all of which are useful folder or terminal windows.

on run
        get quoted form of POSIX path of my getCurrentFolder()
        my termScriptInNewTab("cd " & result)
end run
 
on termScriptInNewTab(cmd)
        tell application "Terminal"
                activate
                set termWins to count of windows
                set frontWin to 0
                repeat with i from 1 to (count of windows)
                        try
                                set tabCount to count of tabs of window i
                                set frontWin to i
                                exit repeat
                        end try
                end repeat
                if frontWin is 0 then
                        do script cmd
                else
                        set frontmost of window frontWin to true
                        tell application "System Events" to tell (first application process whose name is "Terminal") to keystroke "t" using {command down}
                        set xi to 0
                        repeat until (count of tabs of window 1) is (tabCount + 1)
                                if xi ≤ 4 then -- don't wait more than one second
                                        delay 0.25
                                else
                                        set xi to -1
                                        exit repeat
                                end if
                        end repeat
                        if xi is not -1 then
                                do script cmd in (last tab of window 1)
                        else
                                do script cmd
                        end if
                end if
        end tell
end termScriptInNewTab
 
on getCurrentFolder()
        tell application "Finder"
                set theFolder to (path to desktop folder as alias)
                repeat with i from 0 to (count of windows)
                        try
                                get folder of window i
                                set theFolder to result
                                exit repeat
                        end try
                end repeat
                return theFolder as alias
        end tell
end getCurrentFolder

Extra credit: How can you adapt the termScriptInNewTab handler to run the command in the first tab that isn’t busy, rather than a new tab?

How I'm using TextExpander

I’ve always had a problem remember my TextExpander shortcuts, to the point that I wouldn’t use it at all. (The only way I ever found it useful was if I used very obvious shortcuts, but that ran into its own problems when the shortcuts would expand accidentally) With Version 3, I’ve managed to come up with a workflow that meets my need for memorable shortcuts, and that also takes best advantage of its new features.

The first thing I did was changed the delimiter to only be tab. That’s it. No expansions at the end of words or sentences. This makes it work pretty much like auto-complete shortcuts in many text editors. It also lets me put in extremely obvious expansions, so I remember them. (e.g. “rep” creates an AppleScript repeat block, and now I don’t have to worry about expanding when I want to reference a customer service rep in my script’s comments)

The second thing I did was made similar expansions have the same prefix. So the various repeat block snippets for AppleScript, all begin with “rep”. This lets me take advantage of TextExpander’s new “Suggest Matching Abbreviations” feature to quickly pick from many similar options. So I can type “rep” and hit option-V (you can set the shortcut in TE’s preferences), and I’ll get a nice drop down menu letting me select from among Repeat n Times, Repeat Until x, and Repeat with x in y. (Each of which also have fill-ins to make it even cooler) Of course, I can also just type, say, “repw” to get “repeat with x in y”, but I don’t have to remember it.

The one downside of this approach is that I lose the benefit of auto-correction dictionaries that fix common typos and capitalization errors. But I consider this a small price to pay for my increased productivity.

Fix for Software Update "Update could not be saved" error

I’ve occasionally had an error when installing software that goes something like “The update could not be saved… You do not have appropriate access privileges.” I’ve tried deleting the software update caches, fixing permissions, etc., all to no avail.

Well, this Apple discussion thread had the answer. You just have to delete a folder with the same name as your update from /Library/Updates. Or just delete everything, I suppose.

I had to delete the offending folder from the terminal using “sudo” for some reason. I guess it was set as root-owned or something. Weird.

Easily back up gigantic files, even with Time Machine

One place where backup programs really fail is in backing up large files. If, say, your run your VMWare machine, thus updating its disk; you add metadata to a high quality ripped DVD video; or you use Microsoft Entourage, so every time you get a new email, your giant Entourage database gets changed.

Some backup programs can handle block-level updates, so that only the chunks of the file that have changed get backed up, but most don’t.

Well, this little trick on MacOS X Hints is genius! Apple’s Disk Utility in 10.5 lets you create “sparse bundle” disk images. These are just like normal disk images, except that they break up the image itself into numerous smallish files, each one is about 8 MB.

So you can take your big ol’ file, put it into a sparse bundle, and poof! You can now handle backups and it’ll only change a handful of 8 MB files.

While the hint I’ve linked to is pretty complicated, you can just have the image and put large files on it and not worry about the rest of it. You can even just make an alias or symbolic link (type “man ls” in the terminal for a how-to) from one folder to another (yes, this does work on the “Microsoft User Data folder), rather than have a complicated script.

Note that, a few programs that generate big files offer similar features. VMWare, for example, lets you split up your VM’s hard disk image into 2 GB chunks. Not quite as minute as these sparse bundle backups, but still quite good (and probably faster, which is a must-have for a VM). Also, if you’re using FileVault, you already have a sparse bundle containing all your files on your hard drive. Nifty!

MacFUSE vs. ExpanDrive

MacFUSE with SSHFS gives you Finder-level access to your SSH and SFTP servers. It’s been out for a while and is free and open source. Now it’s being challenged by ExpanDrive, which does much the same thing, but costs $29 (at a special introductory price, no less).

So which one is better?

I’ve been using MacFUSE ever since it first came on the scene in order to access my DreamHost web server. For most tasks, I’d much rather copy a file within the Finder than open a custom client program, log into a server, and deal with upload/download target directories, external editors, etc. So MacFUSE’s SSHfs module has been an absolute dream for me.

Of course, it’s also a bit frustrating. It seems like Interarchy’s always just a bit faster at browsing my SFTP server. Copying files seems to send them back home and out to the server again, so a file duplication in the same filesystem that should take a few minutes takes ten or more! And then there’s the times that it just sort of craps out on me for some reason. Those times are rare, but they happen.

So when Daring Fireball tipped me off to Magnetk’s ExpanDrive utility, I decided to give it a try and run it through it’s paces.

The ExpanDrive developers comment that it’s based on MacFUSE, but has been variously improved with better caching and other “secret sauce.” It also handles reconnects after your computer goes to sleep, and claims to deal gracefully with poor network connections..

I gave it some straightforward tests. I opened and edited files; copied large and small files back and forth (and timed the copies); and then did my best to break things by opening disk images on the mounted SFTP drive, expanding and compressing zip files, and duplicating large files.

The results? They’re the same. Really. The same.

I got some slightly different performance on copying small files from the ExpanDrive rather than through MacFUSE if I’d already downloaded them once. This must be the caching they’ve referred to. But the difference was negligible, since it only applied to smaller files.

Both were horrid at duplicating files, and both crashed the Finder once. (It came right back with the remote SFTP drives mounted in both cases)

Now ExpanDrive is very easy to install and use, which definitely scores some points with me. But MacFUSE is no longer a horrid geeky affair to get SSHFS up and running — just a regular package installer and then an SSHFS application that loads your drive with a double-click. You can also use a utility like MacFusion to give you a nice GUI to mount drives. A bit more complex, maybe, but not bad. (MacFusion also re-mounts filesystems after your computer wakes up)

Based on my tests, I’m sticking with MacFUSE and SSHFS. Mostly I just need it as an alternative to an FTP client, and it works fantastically for that. If I were to keep the remote disk up and running all the time (a la my iDisk), then I might be more interested in ExpanDrive’s incremental improvements over the basic MacFUSE setup. (Although I could use JungleDisk — also based on MacFUSE, but using AmazonS3 instead of SFTP — to do the same thing and enjoy the cheapest online storage out there as well as the peace of mind of having all my remote files encrypted)

Regardless, it’s exciting to see all the interesting projects that have come out of the FUSE and MacFUSE projects. There’s just nothing quite like browsing your web server’s image directories using the CoverFlow view and with QuickLook readily available.

Leopard Trick: Spaces Keyboard Shortcuts

When you’re zoomed out to the “all spaces” view, you can drag and drop windows from one space to another to rearrange things. Here’s some keyboard shortcuts to improve upon this feature:

If you hold down the “Command” key while dragging a window, you will move every window of that application within the current space at the same time. (e.g. Every Safari window in the current space will move together, but Safari windows in other spaces with not)

If you do so while holding down the “Shift” key, the window you drag will move to the same location on the screen within the new space. (Especially handy for full-screen windows)

The two keyboard shortcuts can be combined to move all windows of an application to the same location in a new space.

You can also scroll through spaces using your scroll wheel or your two-finger-trackpad-skills while in the all spaces view.

As with all the zoomy eye-candy features of MacOS X, if you hold the shift key down while switching spaces or viewing all spaces, it will do so in slow motion. Oooh!

iDisk improvements in Leopard

In Leopard, iDisk syncing creates a sparse disk image for the sync instead of a standard read/write image. This has the huge advantage that your iDisk sync file doesn’t have to be 10 GB in size, but is instead only as large as it needs to be in order to hold all the files on your iDisk. Very nice.

Leopard Saved Search Irritations

Having faster and more powerful saved searches is great, but I wish they worked a little more consistently.

In the Finder, they show up in the sidebar. That’s great, they’re easy to find and access. However, they’re difficult to browse because they only show up in list or icon view. No column/browser view (my preferred way to quickly navigate folders).

Create Complex Searches in Spotlight

You can do complex boolean searches in spotlight’s search field by including parenthesis, AND, and OR statements. Unfortunately, a lot of metadata is not available via Spotlight’s keyword searches, but is available via the Finder’s search window as “Other” criteria. Luckily, you can add boolean operators using the Find window and an undocumented trick.

One-click to open folders from the Leopard dock

In the Leopard dock, any folders become annoying “stacks.” If you want to open the folder, you need to either open the stack and click the “open in Finder” button, cmd+click it and then open the now-selected folder in the Finder, or right click and select “open in Finder.” Any ability to get to a folder with just one click has been removed.

To get around this, you can make an alias of any folder and put that alias on the dock. The alias will now open with just one click.

LeoColorBar fixes your Leopard menu

MD Softworks has a fabulous little utility called LeoColorBar which fixes the transparent menu “feature” in Leopard. It’s pretty simple, and simply puts a stripe (in a color of your choice) at the top of any picture you choose, and then sets that picture as your desktop background.

It doesn’t modify the original image, but rather stores a copy in your Pictures folder called “LeoColorBarDesktopPicture.jpg” with the appropriate crop settings, etc.

MD Softworks

Time Machine for unsupported setups

My current backup setup consists of a 160GB external hard drive hooked up to a G4/400 Cube. I’m using a combination of ChronoSync and some shell scripts to create a nice archival backup of my home folder. (I don’t bother with apps and stuff because I’m too cheap to get a larger drive.)

Now there’s Time Machine in Leopard, and I’d really rather use it. It’s fully supported, so there’s no need for scripts and hacks, plus it has some nice features with iPhoto, etc.

How I got rid of Airport's auto-connect delay

For the past few weeks, my MacBook has been slow to hook up to my home wifi network. Every time I booted up or woke my Mac from sleep, there would be a short (about 20-30 second) delay before it would properly auto-connect. It doesn’t sound like a big deal, but I have lots of scheduled apps (backups, updates, IM, etc.) and they’d all report errors or fail when they couldn’t promptly find a network connection.

Stop Firefox from downloading everything to the desktop!

Every time I download files in Firefox that I “auto process” (i.e. open with an application or whatnot), it puts the downloaded file on my desktop! This doesn’t happen at home, only at work, and never happens on my PC. Reinstalling Firefox (and extensions, themes, etc. — ugh!) didn’t fix a thing!

Well, thank you Riverside Rugby for showing me how to fix this problem for once and for all!

I have disabled comments due to an overwhelming amount of comment spam, that I cannot seem to stop, no matter how hard I try.

Syndicate content