Blog Archives

Xcode: wrap code in comment tags

While AppleScript’s Script Editor has long had a built-in function for wrapping or unwrapping code with comment tags, for some reason this seems to be missing in Xcode.

Not to worry, nothing a bit of AppleScript and Automator can’t sort out. This will work in most text editors as well as in Xcode. Here’s what it does:

Install the Service by double-clickingΒ on the downloaded .workflow file and clicking through the dialog boxes. When it’s installed, you canΒ assign it whatever hotkey you want in System Preferences | Keyboard | Shortcuts.

Download Toggle Comments for Selection workflow.zip

Screen Shot 2014-11-29 at 12.28.59

If you want to use it for languages that have different comment tags you can adjust the code in Automator. Likewise, it would be fairly simple to have the script detect a number of different tags and respond appropriately, but here I’ve just stuck with the /* …. */ tags.

A note on usage: when uncommenting, it’s best to ensure that the selection begins at the leading forward slash and ends at the trailing forward slash (in other words that there’s no whitespace at either end of the selection). I have built in some attempt to strip leading and trailing whitespace, but an accurate selection will always be the most reliable.

Download Toggle Comments for Selection workflow.zip

Enjoy πŸ™‚

discover 10 new OS X shortcuts

SimpleASEditor

No matter how many times I visit this page, I always find something new that I hadn’t tried before. So the title of this post is more of a suggestion than a description. Why not take a poke around Apple’s shortcut list and discover ten that you don’t already know? I’m going to give a quick round up of ten shortcuts that I use on a regular basis.

1. ⌘ βŒƒ Space
Command-Control-Space is a universal shortcut (i.e., you can use it no matter what application is currently active) for bringing up the character viewer (see the screenshot, top of page). In order for it to work, the cursor must be in a text field where character entry is possible, but you can use it literally anywhere: text documents, search fields, browser bars, save dialogs, etc. I used it heavily in creating this post!

2. ⌘ βŒƒ ⏏
Command-Control-Eject saves you having to trawl all the way up to the ο£Ώ icon top left of your screen and choose ‘Restart…’. It’ll give you the chance to save any unsaved work or cancel the shutdown. This shortcut has a cousin, too: add the option key (⌘ βŒ₯ βŒƒ ⏏ ) to the mix and you get Shutdown instead of Restart.

3. ⌘ ⌫
One of my pet annoyances is continually being asked if I want to save ‘Untitled’ documents, those that I’ve never saved before, when trying to quickly quit an app. Having to take my fingers off the keyboard to move the cursor down to that ‘Delete’ button is time-consuming, and tabbing to it takes multiple hits of the tab key. Fortunately, ‘Command-Delete’ will let you discard the document immediately from the keyboard in one quick shot.

Discard unsafe document

4. ⌘ G
Most people are familiar with invoking ‘Find’ on a page by using ‘Command-F’, but have you ever got annoyed by having to mouse up to those tiny little jump arrows in order to cycle through the hits?

Screen Shot 2013-12-04 at 10.33.11

Save your eyes and use Command G instead! Note that you have to invoke Find with ‘Command F’ first.

5. βŒƒA, βŒƒE, βŒƒK
That’s three separate shortcuts not one! In any text field, Control-A moves the cursor to the beginning of the line; Control-E moves it to the end, while βŒƒK deletes everything from the cursor to the end of the line. Old-hands of the Terminal and other command-line utilities will know these well, but even they may be surprised that these work across a wide-range of GUI apps, too. Particularly useful in Web browser address bars, search fields, Spotlight and so on.

6. ⌘ L
Command-L in Safari and other browser-based apps (including Xcode’s Documentation viewer πŸ˜‰ ) will immediately move the focus to the address bar/search bar and allow you to edit its contents. No clicking necessary!

7.⌘ βŒƒ 1, ⌘ βŒƒ 2, ⌘ βŒƒ 3
Three commands new for Safari’s sidebar. Respectively, open the sidebar with Bookmarks showing, with Reading list showing, and with Shared links showing. Hitting the same shortcut again toggles the sidebar closed. Note that those are the numbers ‘1’, ‘2’ and ‘3’, not F1, F2, F3.

8. ⌘ ⇧ A, ⌘ ⇧ U, ⌘ ⇧ H, ⌘ ⇧ D
Again, that’s 4 different shortcuts, this time for the Finder. OK, hands up all those that switch to the Finder, hit Command-N to open a new window, and then click to their Desktop? Save yourself the grief (and the time), just activate Finder and hit Command-Shift-D. No need to open a window first, the shortcut will open a new window for you showing your Desktop folder. The others do the same thing but for different folders: Command-Shift-A opens your Applications folder, Command-Shift-U the Utilities folder, Command-Shift-H opens your Home folder.

9. ⌘ F1
This one’s for those of you with dual monitors or when your Mac is hooked up to a projector. Command-F1 toggles between mirroring and separate monitor views. Great for presentations.

10.(fn) βŒƒ F8
Control-F8 activates the Status bar (top right row of icons on your screen). Use the left/right arrow keys to move along them, and the up/down arrows to select things in any menu. Hit ‘enter/return’ to perform the action. Note that on laptops you may need to invoke the fn ‘Function’ key, depending on your settings in Keyboard Preferences.

This is a great one for turning on/off Bluetooth, Wifi and checking Mavericks’ new Energy monitor in the Battery/Power icon. Mostly though, I use it for manually starting Time Machine backups or entering TM’s “star wars” interface (oh, and as a bonus…note that (fn) βŒƒ F2 activates the other side of the menu bar (i.e., the ο£Ώ menu). Enjoy!

Screen Shot 2013-12-04 at 11.09.14



Got your own favourite shortcuts? Tell us what you use most in the Comments! πŸ™‚


restore tab & spacebar keys in logout window

Image

If you did a clean install of Lion at any point you might have noticed that the spacebar won’t toggle the checkbox and tab won’t cycle through the options in the Logout window.

To resolve this, open Terminal.app (Applications > Utilities > Terminal.app) and copy/paste this command

sudo defaults write NSGlobalDomain AppleKeyboardUIMode -int 3

Press ‘return’ and type in your Admin password. Restart your computer and your tab and spacebar keys should be back to normal!

πŸ™‚