Compiling C console applications for Android (on Mac OS X)

I wanted to build some C applications on my Mac, to run directly on the console in Android. It’s possible to do this using the ARM toolchain, but it can be a bit hard to work out how to do it. Having got it working, I’ve written down a simple process that should allow you to get up and running very quickly. Continue reading

Posted in Android, Mac | Tagged , , | Leave a comment

Mac OS X mute startup sound

I’ve been looking for a way to mute the startup sound on my MacBook Air. A lot of people claim that Apple deliberately make this sound unmutable as it acts as a diagnostic check on boot, similar to the beeps on a PC. However, this doesn’t really make sense, because the sound will not play if at the time of the last shutdown the volume had been muted. So it can’t be relied upon as a diagnostic. (“Either this Mac is broken, or you had the sound muted when you shut down. I can’t tell which.”)

Some people also say that if you’re going to be using your MacBook in a place where you need to be quiet, then you should ensure that you’ve muted the sound before you shut down. But this doesn’t make sense either, because you don’t always know when you shut down that the next place you’ll be turning it on is a quiet place.

Anyway, I found a method on the MacScripter forum which solves the problem quite nicely by muting the sound automatically upon logout. AppleScript is a technology that I’ve not really used much before, so I’m not aware of all the things that can be done with it. Looking through some sample scripts, it does seem to be a powerful tool for automating Mac tasks (and it’s been around a very long time, so there are lots of examples to play with).

Of course, this method only works if the logout process executes. It won’t be able to mute the sound if Mac OS crashes! But it will catch the overwhelming majority of cases.

Here’s how to mute the boot sound. (I’ve only retained the “logout” part of the solution, as that’s the only bit that I care about.)

Create a plain text file with the following as the logout script:

#!/bin/bash
/usr/bin/osascript -e 'set volume with output muted'

Save the script as /usr/local/bin/logoutscript .

In Terminal, run the following command:

sudo chmod a+x /usr/local/bin/logoutscript
sudo defaults write com.apple.loginwindow LogoutHook /usr/local/bin/logoutscript

If you want to remove these changes later, do this:

sudo defaults delete com.apple.loginwindow LogoutHook
sudo rm /usr/local/bin/logoutscript
Posted in Mac | Tagged | Leave a comment

Stop MacOS X Lion Office reopening old documents

UPDATE: This doesn’t seem to work any more. I now just have the setting “Close windows when quitting an application” set in System Preferences – General.

System Preferences

Original post:

On Mac OS X Lion, Microsoft Word reopens previously edited documents when you start it up. This can be very annoying.

To stop it, run this:

defaults write com.microsoft.Word NSQuitAlwaysKeepsWindows -bool false

You can substitute different applications for com.microsoft.Word. You can find the names in ~/Library/Saved Application State.

If you want to fix all the main Office apps (and Preview) in one go, run this script:

#!/bin/bash

function runit
{
defaults write $1 NSQuitAlwaysKeepsWindows -bool false
}

runit com.microsoft.Word
runit com.microsoft.Excel
runit com.microsoft.Powerpoint
runit com.apple.Preview
Posted in Mac | 3 Comments

Setting up VNC on Raspberry Pi for Mac access

I wanted to set up VNC on my Raspberry Pi so I could use it via a remote desktop on my MacBook Air. There are lots of instructions scattered in various places around the web, but now I’ve put together a comprehensive set of things to do, I thought it might be useful to share it in one place. Continue reading

Posted in Mac, Raspberry Pi | 55 Comments

Bash script to copy Raspberry Pi disk image to SD card

English: Image of the front and back of an 8GB...When you’ve downloaded a disk image for your Raspberry Pi, you need to copy it to your SD card. You can follow the simple instructions, but if you have to do this a lot it’s easier just to have a script that does it for you.

I wrote this script for use on my MacBook Air. It takes the disk image file as a parameter, e.g.

./copytocard debian6-19-04-2012.img

NOTE: The disk devices could be different on your computer. This script could wipe out the wrong disk if the wrong device numbers are used. I’m providing the script for convenience; please ensure you check it carefully before using it on your own computer. Take a look at the simple instructions so you can check which device numbers you need.

#!/bin/bash
[[ $# -eq 0 ]] && echo "I need an image file" && exit 1
IMG=$1
echo -n "Waiting for card"
df -h | grep disk2s1
RES=$?
while [[ $RES -gt 0 ]] ;
do
  echo -n .
  sleep 1
  df -h | grep disk2s1 > /dev/null
  RES=$?
done
echo
echo "Disk found"
echo "Unmounting..."
diskutil unmount /dev/disk2s1
echo "Copying (please wait)..."
dd bs=1m if=$1 of=/dev/rdisk2
echo "Ejecting..."
diskutil eject /dev/rdisk2
echo "Done. Remove card."
Posted in Raspberry Pi | 2 Comments

Mac OS X + FileVault 2 + Safe Boot… Don’t!

A word of warning…

If you use FileVault 2 (full disk encryption) on your Mac, you might be tempted at some point to perform a Safe Boot by setting the boot flag:

sudo nvram boot-args="-x"

Don’t!

What will actually happen is that the Mac will enter an endless cycle of rebooting every time you enter your password to unlock the disk.

If you have done this, then the way to get out of it is to reset your PRAM like this:

Do a reboot, and immediately hit P R together (Option + Command + P + R), and hold them down until the Mac reboots again. Now it should boot up normally.

If you need to perform a Safe Boot, Apple say that you should disable FileVault 2 first. (I have not tried this.)

Posted in Mac | 2 Comments

Raspberry Pi

I finally got hold of my first Raspberry Pi.

This morning I’ve burned a Debian “squeeze” distro to the SD card, and performed an initial boot just to check that it’s working. The next step is to set up a proper development environment for experimentation. I have some ideas for projects, but most of them require some extra hardware that I don’t have to hand right now.

Posted in Raspberry Pi | 1 Comment