What do you do when you browse the web and meet a brilliant code snippet? A good idea would be to store it quickly so you can find it later.

Snippets application helps you do just that and provides a number of ways to add new code into the Library. First, you can drag & drop the text content right into the Snippets main window. Next, you can drag & drop right into the application Dock icon. And finally, Snippets application is fully integrated with Mac OS X Services.

You might want to know: Services are operations declared by installed bundles and available system-wide to all applications. Prior to Snow Leopard this feature hasn't been very popular. But the latest Snow Leopard release has changed the situation completely. Services have been refined and it is now a real pleasure to use them. For example, you can select some text within Safari browser and use context menu to ask Services to speak it aloud. Isn't it cool?

How can it help you? Services technology allows you import new items into Snippets application even quicker. Every time you meet a worthy code snippet on the web you just select it on the page and choose the services menu item ‘New Snippet With Selection’. Voila, it is saved in the Snippets Library!

Below you can find instructions on how to enable this feature and use it.

1. In any application, open ‘Services Preferences…’ via Services menu

open ‘Services Preferences…’ via Services menu

You may also enable and disable Services via standard ‘System Preferences’ window by opening ‘Keyboard—Keyboard Shortcuts’ pane.

2. Select ‘Services’ item on the left Select ‘Services’ item on the left

Right part of this window displays a list of all services (declared by applications) available in the System.

3. Locate ‘New Snippet With Selection’ service in the ‘Text’ group Locate ‘New Snippet With Selection’ service in the ‘Text’ group

Mac OS X only scans for new services after you log in, so the ‘New Snippet With Selection’ service may not be in the list yet. If that is the case, you can manually force service list update.

You have 2 different options to do this:

  1. Log off from your user account session and log in again
  2. Launch Terminal application (located in the /Applications/Utilities folder) and paste the following console command
/System/Library/CoreServices/pbs

then hit Enter to run it and refresh the list of available services.

4. Turn on ‘New Snippet With Selection’ service Turn on ‘New Snippet With Selection’ service

Selecting the check box will make ‘New Snippet With Selection’ service available for all Cocoa-enabled applications. In addition, you can bind a custom system-wide keyboard shortcut to run the service.

5. Test the Service

Test the Service

Select a code snippet in any Cocoa application (like Safari) and right-click it to display the context menu. Then find services available in the particular context at the bottom.

And click on the ‘New Snippet With Selection’ menu item. Snippets application will open with a new snippet created from the text you selected in Safari.

P. S. Some applications (like Adobe authoring tools) disable Services menu item. In this case you can use other ways to make a new Snippet from the selected text (i. e. drag & drop it directly on the Snippets app icon in the Dock).