Computer Science York University CS Student Blogs

Creating a Useful and Awesome Screen Saver for Mac

This summer I spent a lot of time working in the Library and wanted to be able to keep my laptop open so I could quickly refer to it, whilst keeping it locked.  Of course, the obvious choice is a screensaver, but they’re all pretty boring – static content, never changing day-to-day, and never useful.  So, as someone who loves Google and has a problem with the size of their inbox, I came up with this – a screensaver that shows currently entered Google Searches (from Google Trends) and the number of items in my inbox, along with a coloured background to indicate if I’m doing well (it’s always always red at the moment).  Check it out below:

It’s very easy to create – all you need is:

  1. A Gmail inbox that you want to keep clear
  2. A PHP file to check how many emails are in your inbox and to change background colour (and a server to run it on, whether remote or local).
  3. A HTML file to bring this together with the Google searches.
  4. WebSaver

(1 and 2 could easily be combined to save the use of an iframe, and this is not great code – but it works).

For the PHP file, you’ll need to fetch the number of items in your inbox (using your mailbox password) and echo back the appropriate page background colour.  I do this with:

/* connect to gmail */
$hostname = '{}';
$username = '<Your gmail or Google Apps email address>';
$password = '<Your Gmail Password or device-specific password (for 2 step)>';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'ALL');

if($emails) {
        if (sizeof($emails) < 100) {
        echo '<body style="background-color:green">';
        } elseif (sizeof($emails) < 150) {
        echo '<body style="background-color:orange">';
        } else {
        echo '<body style="background-color:red">';
        echo '<div style="width:200px; height:200px; margin:auto; position:absolute; top:0; bottom:0; left:0; right:0; color:white; font-family: Verdana; font-size: 50px;" align="center">' . sizeof($emails) . ' Emails</div>';

Note, where I have set my username and password at the top, and that I have set the level for doing badly (a red background) as 150, and the level for doing OK (a orange background) as 100 (less than that is good, so I get a green background).

In the HTML file, I simply create an IFrame to this page and the page containing the cool Google searches (simply replace below):

iframe {
        width: 49.89%;
    height: 100%;
body {
    margin: 0px;
    border: 0px;
<iframe src="<path to your PHP file>" frameborder="0"></iframe>
<iframe src="" frameborder="0"></iframe>

Finally, set your new webpage as your screensaver. Simply download the WebSaver, install it, open Screen Saver options from System Preferences on your Mac, and click on WebSaver on the left. Then click “Screen Saver Options” and enter the URL to the HTML webpage for your screen saver.

Voila, done! Enjoy your awesome screensaver.

(On a final note, I configured a keyboard shortcut on my system of “Command+Alt+.” to activate the screensaver, so I could quickly lock my screen.

Computer Science programming University

Building and using OpenCV with Eclipse on Mac OS X

This took me a little while to figure out due to the sometimes subtle differences in Mac OS X and Linux, and the imperfect documentation.  Eventually I got it working though. The goal was to build OpenCV for Mac OS X 10.9 and then get it working in Eclipse. So, here goes:

  1. Ensure you’re using a JDK with version number 1.7 or higher.  If not, see here for instructions.
  2. Download the latest version of OpenCV (I used 2.4.8, so if you have problems, try going back this) from here, for Mac.
  3. Extract it.
  4. cd into the extracted directory of OpenCV in your terminal and execute the following:
mkdir build
cd build
cmake -G "Unix Makefiles" -D CMAKE_CXX_COMPILER=/usr/bin/g++ -D CMAKE_C_COMPILER=/usr/bin/gcc -D WITH_CUDA=ON ..
make -j2

(Note in the above, -j2 refers to the number of CPU cores I had – e.g. set to -j4 if you have 4 logical cores).

Then just look in build/bin, and you’ll see a .jar at the bottom – congratulations, you just built OpenCV! Import this as a library into Eclipse, and set the native path also to build/bin, and you’re done.

If you get stuck, let me know in the comments and I’ll do my best to help.

Computer Science programming

Installing JRE {7,8} / JDK {1.7,1.8} On Mac for Eclipse

As part of my Software Engineering Project (SEPR) for my course, I’m working on a game with my teammates in Java.  Unfortunately, even with the latest release of OS X (10.9.2), Apple still only provide you with the JDK V1.6, which is quite old and lacks some commonly used features from 1.7 and 1.8.  Although installing it isn’t exactly complicated, it’s not obvious how to link it into your system, and I couldn’t find a manual for doing this with Eclipse.

Now that I’ve found out how to do it, it makes sense to share it to potentially save you some time:

  • Download the latest version (JRE 8, JDK 1.8 at the time of writing) from here.
  • Install it – it should install automatically to a path similar to:
/Library/Java/JavaVirtualMachines/jdk1.8.0_<more numbers>.jdk/Contents/Home
Note, the above scrolls, it ends with '/Home'
  • Open Eclipse, and in the top menu go to Preferences->Java->Installed JRE’s-> and click the add button.
  • Then select “Standard VM” and click next.  Give it the install path from above for the “JRE Home” parameter and click Finish.  Now you can select the new upgraded JRE/JDK for your projects in Eclipse.

I hope that helps.

Computer Science Google Glass

The Last Resort – Finding the MAC Address of Google Glass [UPDATED]

UPDATE: The Glass Team have recently made this a whole lot easier (I guess in response to a lot of requests).  Your MAC address is now available on the MyGlass page.  Just visit, and click on “Device info”.  It’s listed below:

Finding the MAC Address of Google Glass
Finding the MAC Address of Google Glass

Original post:

So, today I needed to find the MAC address of my Google Glass so I could get an exception made on a Firewall for screen casting at an upcoming conference (Venturefest York). This was more difficult than expected (partly because of Glass, partly because of my situation), so I thought I’d explain the method that’ll reliably work for people in a similar situation.

Jump to the solution, or read what I tried first:

On most pieces of technology with networking functions, the MAC address is printed on the side of the packaging.  Saying that, I can’t think of a piece of technology where this hasn’t been the case for me.  Unfortunately, in this age of ‘Unboxing is Theatre’ and minimalistic packaging, Google omitted this on the Explorer Edition.

So, the first normal step then would be to go to the Settings app (if on a desktop or mobile device) or the control panel (if it’s a networking device) and find it there, but since Glass has such a (beautiful) minimalistic design, information not vital to the day-to-day operation of Glass is hidden.

Next, you’d normally look in your router’s control panel and find a connected device with a name matching the name of your Glass.  Unfortunately, I’m on a large organisation network without access to this kind of control panel.  I experimented with creating a personal hotspot from my phone for Glass and a Laptop, but then when I queried Glass for it’s MAC address with the arp utility it returned nonsense.

So, the solution.  You’ll need to open a shell on the device and execute the Android Network Configuration application.  To do this:

  1. You’ll need the ‘adb’ utility – download the Android SDK if you don’t have it.
  2. Enable dev/debug Mode on your Glass (Settings -> Device Info -> Turn on debug).
  3. Plug Glass into the computer you’ve got adb installed on.
  4. Run the following in your terminal:
adb shell

and the output will include the MAC address of your Glass:

[email protected]:/ $ netcfg
lo       UP        0x00000049 00:00:00:00:00:00
ifb0     DOWN      0x00000082 ff:ff:ff:ff:ff:ff
ifb1     DOWN      0x00000082 ff:ff:ff:ff:ff:ff
sit0     DOWN      0x00000080 00:00:00:00:00:00
ip6tnl0  DOWN      0x00000080 ff:ff:ff:ff:ff:ff
wlan0    UP       0x00001043 ff:ff:ff:ff:ff:ff

(where ff represents obscured values)

So there we are!  Easy once you’ve found how to do it.