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!

Pages

Subscribe to RSS - Stupid Mac Tricks