Monthly Archives: March 2014

advanced search in Preview


Unlike Adobe Acrobat, you won’t find any complicated advanced search boxes in Preview, but that doesn’t mean you have any less power to find exactly what you want. Feel free to open up a pdf that you can play around with as we go along.

Finding stuff
Preview does all its searching in the spotlight-like filter field in the top right, and you access it either by clicking in it or hitting ‘command-F’.

Simply typing in a few letters will return every page that contains that string, either as a word or a partial word. If you want to restrict the results to complete words – say you type in ’cause’ but you don’t want it to return ‘because’, then add double quote marks around what you type.


If you add another word (or words), also in double quotes, this is effectively telling Preview to return only those pages that contain all those complete words on the same page. Thus

"cause" "pattern" "function"

will only return pages in your pdf document that contain all three of those terms. This is the same effect you get when you put the ampersand ‘&’ between words (the logical AND), but the & is automatically implied by default, so there’s no need to actually type it.

What if you want to return all pages that have either “cause” or “function” in them? In this case, you use the ‘|’ sheffer stroke (hold down shift and hit the backward slash key, up their above the return key!).

Note for the techies: Preview doesn’t distinguish between NOR and NAND. Though both are valid input, one sheffer stroke will return the same as two.

As with the logical ‘AND’ function, you can have as many terms as you want. For example, if you wanted to return every page that had a numeral in it, you could use

"1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0"

That would return every instance of any one of those digits on their own, but it wouldn’t return a page that had, say, ‘2014’ in it. Remember that the quote marks indicate whole expressions, not parts. To get any number, do the same without the quotes:

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0

You could even combine this with word searches:

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | one | two | three | four | five | six | seven | eight | nine | "ten" | eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen | twenty | thirty | forty | fifty | sixty | seventy | eighty | ninety | hundred | thousand | million | billion | trillion | zero | nought | nil

That would return every mention of any number in numerals or words. Note that “ten” is delimited as a complete word due to the number of false positives that would arise from words with those three letters (heighten, often, tendency, etc). Also notice the various synonyms for ‘zero’ at the end of the search term. Even so, it isn’t quite complete – the assiduous search-hound would probably want to add ordinals, ‘1st’, ‘first’, ‘2nd’, ‘second’ and so on, but I’ll leave that as an exercise for the reader.

Organising results
OK, so you’ve got your results, what can you do with them? First of all, note that you’ve got some options above the search sidebar. You can list by page order from beginning to end of the document, or by number of hits per page with ‘Search Rank’. Highest number of matches on a page appears at the top of the results and the rest follow in descending order.

Screen Shot 2014-03-22 at 00.10.14

Secondly, you can cycle backwards and forward through the hits on each page by using ‘command-G’ and ‘command-shift-G’, respectively. That’s a whole lot less laborious than clicking the tiny forward and backward arrows under the filter field, but that way is available too.

filter bar

The filter field
Finally, don’t forget that you can move the cursor around in the filter field with a few shortcuts: both ‘control-E’ and command-right arrow will put the cursor to end of the search term, while ‘control-A’ and command-left arrow will put it at the beginning. You can also use ‘control-K’ to delete everything from the cursor to the end of the search term, which can be handy if you have a lengthy search term that you want to cut in half. Move the cursor to where you want the search term to end, and hit ‘control-K’ to delete all subsequent characters.

Hopefully, that should give you some pretty good ideas on how to power search in Preview. Who needs ‘advanced search’ dialog boxes? Not us! 🙂

featured picture: searching for light by HealingRock


Contacts won’t launch

Screen Shot 2014-03-04 at 21.42.46
I’ve seen this problem crop up from time to time, and it seems to have reared its head again with the 10.9.2 update *.

Try running the following script in AppleScript editor:

tell contacts to activate

If you get an error message back from the AppleScript editor mentioning error number -10661 has occurred, then you’re going to need the following procedure.

The problem stems from the launch services database being out of sync and not knowing which app to launch when it gets passed “Contacts” as input. To solve that, we’re going to do a couple of things in Terminal (roll up your sleeves!).

First up, we’re going to ensure that the locate database is loaded. We’re going to need that to find the address of the Launch Services database, so

1. Open (/Applications/Utilities/ and type

locate lsregister


You should get one of two possible results. Either you get a message telling you that the locate database doesn’t exist, and instructions on a command to run to create it:

sudo launchctl load -w /System/Library/LaunchDaemons/


or you get a path back that looks something like



In the first case, use the command suggested in the reply to create the database. The Terminal prompt will probably reappear almost instantaneously after you run that, but your database may not have finished creating yet. Wait a few minutes before running the ‘locate lsregister’ command again.

In the second case or once you’ve got your locate database loaded and working, copy the address returned to the clipboard by dragging across the whole thing to highlight it and hitting ‘command-C’ on your keyboard.

Still with Terminal active, hit ‘command-V’ to paste that address at the prompt. Hit the spacebar once, and then complete the command by adding

-kill -r -all l,s,u


So the whole thing should look something like this:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -all l,s,u


Finally, hit ‘return’ to enter the command. It’ll take a few seconds to return the prompt (it’s about 10 seconds on my machine, but your mileage may vary).

After the prompt returns, go test that AppleScript again. Hopefully, Contacts fires up without issue. 🙂

*Thanks go to Yvan and Deivy on the AppleScript users list for identifying and solving this problem.

%d bloggers like this: