Wednesday, 26 February 2014

In XCode 5, turn on 80-column line guide


I am using XCode 5 and the coding style guide that I am using requires avoiding lines going past the 80-column mark, if possible.

How do I turn on the 80-column guide?


  1. Go to the XCode Preferences (in the menu: XCode -> Preferences...)
  2. Go to the Text Editing tab
  3. Check "Page guide at column: "
  4. Change the number to 80, or to whatever column your required style guide needs

Friday, 21 February 2014

Toggle Doxygen in Eclipse Kepler CDT C/C++ Editor


I'm working on C/C++ in Eclipse Kepler and I would like to toggle the IDE editor's Doxygen comment helpers as they appear to be turned off by default. How do I do this?


To toggle the "automatically generate Doxygen comment" feature in Eclipse, go to:

Preferences ... -> C/C++ -> Editor

Then look for the panel labeled Documentation tool comments and change Workspace default to "None" or "Doxygen", depending on your preference.

This is illustrated in the following image:


If you are unsure of what Doxygen is, check out this quick explanation from Wikipedia (as of Feb 21, 2014):

Doxygen is a documentation generator, a tool for writing software reference documentation. The documentation is written within code, and is thus relatively easy to keep up to date. Doxygen can cross reference documentation and code, so that the reader of a document can easily refer to the actual code.
Article link: It's a fairly useful tool and you should consider using it if you don't already have a consistent style for writing comments in C++ code.


Monday, 3 February 2014

How to detect displays in OS X 10.9 Mavericks


How do I detect displays in OS X Mavericks? The Systems Preferences option to detect displays seems to be missing.


While in the "Displays" Systems Preferences panel, press the "option" key and the "Detect Displays" button will appear when using OS X Mavericks.

Image below: OS X 10.9 Displays panel with the "Detect Display" button missing by default

Image below: OS X 10.9 Displays panel after pressing the "Option" key


This was tested to work in OS X 10.9 and 10.9.1. Your mileage may vary in other versions.


Monday, 13 January 2014

Check if music is already playing on Android from within an Activity


How do I check if music is already playing on an Android device from within an Activity?


AudioManager aMan = (AudioManager)this.getSystemService(
if(aMan.isMusicActive()) {
  // do stuff here if music is playing


This check can be useful if your app needs to play music. This is because there are instances where attempting to play music using MediaPlayer while music is already playing will corrupt an audio stream on an Android device.


Tuesday, 7 January 2014

Disable Mac start-up chime in OS X 10.9 Mavericks ("Band-Aid" workaround only, for now)


I would like to disable the start-up chime my OS X Mavericks-based Mac makes so that restarting the computer will not be so loud.


  • The solutions below were tested on OS X 10.9 Mavericks and may work on other versions, but there is no guarantee.
  • This how-to was written as a reminder for myself in case this needs to be replicated or undone later. It is not a full solution and still a bit advanced for the average OS X user to follow, which makes it unacceptable to post as a "solution" (in my opinion).
  • You're welcomed to follow the solutions below, but use the more permanent one at your own risk.

Solution 1 (temporary):

Turn the volume of your computer down before shutdown or restart. The start-up chime should match your system's volume.

Note that muting seems to have mixed reported results in forums and other online posts, where some systems will chime at the same volume as the system volume, even when muted (resulting in lots of surprise chimes), yet others report that muting works.

Solution 2 (advanced workaround, but a bit more permanent):

This solution goes through the steps to write a script that turns the system volume to 0, and rigs it to run upon the user selecting to shutdown or restart the machine via the apple menu.


  • Make sure you are comfortable with Terminal, shell scripts, file permissions, and reading manual pages (if you get stuck). If you are not comfortable using Terminal (or are prone to making typos), you should probably not try this. Attempt at your own risk.
  • Every time you start up OS X, the volume will be set to 0 (which may not be a bad thing if you're already trying to avoid surprises by turning the chime sound off to begin with)

This is a modification of the solution found here, but modified in a way that should work on more OS X setups. The modified steps are posted below as a reminder in case the link ever goes down.


  1. Run the Terminal app with an administrator account
  2. Create a script for muting (replacing "/path/to/" with a valid path -- if you're not sure what this means, do not proceed with the rest of the steps)
    sudo nano /path/to/
  3. Write the volume-off script (or copy and paste the following into it):
    osascript -e "set Volume 0"
  4. Make file executable with following command (replacing "/path/to/" with where the script is saved):
    sudo chmod u+x /path/to/
  5. Check that we can hook this to the OS X logout (see if any hooks exist - only one or none can exist, not more). In Terminal, use the command:
    sudo defaults read LogoutHook

    You should end up with something similar to "The domain/default pair of (, LogoutHook) does not exist".

  6. Add hook to run script at logout, replacing "/path/to/" with where the script is saved:
    sudo defaults write LogoutHook /path/to/

To Undo Solution 2:

  1. Check that the logout hook exists in Terminal with the following command:
    sudo defaults read LogoutHook

    You should end up with something similar to "/path/to/" with "/path/to/" being where your script is saved.

  2. Delete the logout hook in Terminal with the following command:
    sudo defaults delete LogoutHook

Notes on solution 2:

  • Just like in the original solution, the script is also saved in /Library/Scripts/
  • Make sure the permissions of the script is set so that only the owner can write to the file, since the script is run as sudo (and would be an obvious security risk if it can be re-written by just anyone).
  • The script must be owned by root.
  • Again, this will turn the volume to 0 upon logout rather than simply mute. This is because many people online seem to report mixed success with muting.
  • The commands for setting both a login and a logout hook, as well as removing them are as follows:
    • sudo defaults write LoginHook /path/to/
    • sudo defaults write LogoutHook /path/to/
    • sudo defaults delete LoginHook
    • sudo defaults delete LogoutHook
  • The commands for checking if a hook exists for login or logout are as follows:
    • sudo defaults read LoginHook
    • sudo defaults read LogoutHook

Very brief discussion on problems with other solutions found online:

The following will only make sense to anyone who has Googled how to disable the start-up Mac chime and read through the various proposed solutions. It briefly outlines why these workarounds weren't posted here. You can skip this section if you'd like.

nvram SystemAudioVolume method:

  1. too dangerous for most users (you can easily accidentally turn your computer into an expensive paperweight with the nvram command)
  2. many mixed results and uninformed posts online on why that solution used to work (read: everyone seems to be guessing. If you don't want to be one of those guessers, you can read up on nvram in the slightly out-of-date book "Mac OS X for Unix Geeks (Leopard)" in Google Books as that section appears to be viewable for free, at least as of January 2014)
  3. the solution doesn't work on all OS X and Mac combinations
  4. the solution does NOT work in Mavericks (tested) as the system will change the SystemAudioVolume value automatically

rc startup/shutdown script method:

  1. does not work in Mavericks as start-up has been moved to launchd instead (see Apple developer documentation on Launch Daemons and Agents
  2. any daemon-supporting mechanism may change in future versions of OS X, making this solution possibly unreliable (and worse, it will leave potentially unwanted files dangling deep within the system)
  3. this solution is way too complicated to post for the average user

existing software:

  1. many don't work on all versions of OS X (mixed results reported in forums, etc.)
  2. all software Googled do not describe exactly what system-wide changes are being made, making it hard to determine how permanent they are, as well as how well do they handle OS upgrades
  3. Mavericks seems to have broken a lot of the existing software, so it's hard to recommend a good one

the solution 2 in this blog post:

  1. it's not possible to do if you are not the system administrator
  2. it's not possible to do if you or your system administrator has already hooked something to LogoutHook
  3. it's possible that it won't work if you shut down your computer using a different mechanism than the usual Apple UI ways
  4. it's still inaccessible to most users
  5. if permissions are not set correctly, you could potentially create a security hole

an official Apple "turn off start-up sound" preferences item:

  1. does not exist/was eliminated
  2. if you're from Apple, perhaps you could help out with this? =)


Wednesday, 1 January 2014

First one-line post of 2014! Thanks for over 50,000 views!

Happy New Year and Thanks for over 50,000 views (I know it's not many views, but it still feels great that some of you have found the posts useful)! =D

Friday, 6 December 2013

Create an ISO disk image from a CD/DVD in OS X


I would like to back up a disc to an ISO image using OS X. (This can be useful when backing up personal content such as photo albums, home movies, etc.)


  • Insert disc into disc drive
  • Open the "Disk Utility" application (Application -> Disk Utility)
  • Select your disc drive
  • Click on "New Image" (one of the buttons on the top of the window)
  • For "Image Format", select "DVD/CD master" (on the bottom)
  • Pick a filename and click "save". This should create a file with a .cdr extension
  • When the image is done being written to disk, rename the extension to .iso


  • If the original image does not have an extension .cdr, but instead has an extension .dmg, etc., "DVD/CD master" was not selected. Restart the process, but this time select "DVD/CD master" as the image format.


This should work on most versions of OS X until 10.9, and possibly even beyond. This how-to was tested to work using OS X 10.7 through 10.9.


This how-to was adapted and condensed from the link below. It was written as a reminder, in case the page below ever goes down.

Thursday, 5 December 2013

Workaround to place XQuartz/X11 apps on second monitor in OS X Mavericks (apps like Inkscape)


I've upgraded to OS X Mavericks and I can't place apps such as Inkscape on my second monitor any longer. I don't want to turn off "Displays have separate Spaces."

Before trying this workaround ...

This workaround was written as a reminder for myself. Even if you get it to work, X11 programs will be riddled with bugs because of how Mavericks currently treats Spaces coordinates, gravity, etc., with XQuartz. Thus, I'd recommend not following it for the time being unless you're curious. A better workaround is to simply turn off "Displays have separate Spaces" in: System Preferences ... -> Mission Control

This workaround only works under very specific conditions right now, and there is no guarantee that it will work under other conditions. The following are the conditions under which this workaround worked:

  • The OS X Team nor the XQuartz team have not addressed the issue yet (test this out to make sure that you're not using a workaround when things actually work)
  • OS X version is 10.9
  • XQuartz is installed and works
  • XQuartz version is XQuartz 2.7.4 (xorg-server 1.13.0) or under (haven't tested it with newer versions, and newer versions may fix this problem rendering this workaround pointless)
  • Inkscape and other X11 apps run
  • "Displays have separate Spaces" is checked under: System Preferences -> Mission Control
  • You haven't already dragged the application window out of bounds in one of your spaces (in which case you'll need to figure out how to reset its position first -- can't help there at the moment since each app handles its position in different ways. Advanced: Try resetting or reinstalling the X11 app, or editing its config file?)
  • You know what the following terms mean: "dock", "desktop", "mission control", "spaces", "X11", "XQuartz", "secondary click"

If you're here to try to get Inkscape or other X11 apps to work in Mavericks in the first place, try this post first:


This is hardly a permanent solution, nor is it guaranteed to work under all versions of OS X, XQuartz, etc. This workaround is just posted here in case anyone else finds it useful to be able to use X11 apps on their second monitor once again after upgrading to Mavericks, and doesn't mind jumping through a few hoops. Hopefully by the time you read this, someone at Apple or XQuartz would have fixed this issue. (If you're one of said Apple or XQuartz people, please fix this =) lol.)

Also note that because the bug seems to be related to coordinates, weird things can happen with this workaround, such as windows, child-windows, etc., opening out of bounds and therefore off-screen. Hopefully someone out there will be able to debug this problem as this workaround can't work around bugs like that.


  • Launch the X11 app so that XQuartz and the app's icon show up in the OS X dock
  • In the dock, secondary click the XQuartz icon and select: Options -> Assign To: None
  • In the dock, secondary click the app icon and select: Options -> Assign To: None
  • Go to mission control (hit f3 on most Macs, or triple-swipe upwards if that gesture is enabled)
  • Do NOT attempt to drag the app to the space/desktop on the other monitor as you do with native apps, as all this will do is set the window out of bounds on the current space/desktop. (At least, as of XQuartz 2.7.4 (xorg-server 1.13.0) or earlier.)
  • Drag the X11 app window (such as Inkscape's window) to the desktop/space mini-window on top of the other monitor (the one on top with the labelled "Desktop __" with the desktop number in place of __ -- not to the big desktop area below)
  • If all worked out, the app should now actually display on your second monitor
  • (Optional step - if you work for Apple) Program a patch to allow drag-and-drop of X11 apps to spaces residing on second monitor
  • (Optional step - if you work on the XQuartz project) Detect bounds of monitors and imitate native drag-and-drop behaviour (I'd like to help out, but I'm not entirely sure how to right now =/)


As this issue hasn't been solved yet as of the time this post was written, I've decided instead to link to the closest bug report that I could find:

If you happen to have a better fix, please feel free to update us all in the comments below! =)