Sunday, May 9, 2010

iOTP and more

Hi,

I haven't written here for quite a time. I'll post now a few stuff I've written over the time:

  1. iOTP — I like this one. I study in the Hebrew University in Jerusalem, and we have a one-time-password thing for logging in to the University servers and stuff like that. The bad thing is that the application which generates these OTPs is a Java applet for Nokia phones. The only other option for getting OTPs is by logging into a website and getting an SMS with the next 5 OTPs.

    A nice guy reversed this OTP generator to a Python script.

    I wrote an app this week which generates these OTPs right on your iPhone.

    The sources are available here, and there are some screenshots: (1), (2).
    Of course I don't have $100 to spare, so you can install it only on Jailbroken iPhones, by connecting to a Cydia repository I created on: http://www.cs.huji.ac.il/~brick/cydia http://cydia.myrepospace.com/brick/.

  2. Another couple of scripts for Messenger Plus:
    MessengerLastFM — this sets your personal message according to your now playing track on last.fm. You can get it here.

    MessengerRefetchDPs — this refetches your contacts' display pictures when they log in. I made this because somehow mine stopped refreshing :S. You can get it here.

Cheers,
Tomer

Tuesday, January 6, 2009

MotionPong

Hi again,

A friend of mine wrote a 3D Pong game using the cross-platform Allegro library. I decided it would be nice to play with the MacBook Sudden Motion Sensor so I integrated it with UniMotion.
I'd upload the code, but the SMS part is really simple, and the original code is REALLY messy. Instead, here's a link to the actual game: MotionPong.

Have fun,
Tomer

Edit: I added a 2 second wait after one side scores, so that you could reorient your MacBook in the center.

Saturday, January 3, 2009

WinPopup Quicksilver Module Revised

Hi, wandering Googler.

I haven't wrote anything new for quite a time. This is because I joined the army in the end of July, and I don't have a lot of time to write new stuff.

I did, however, find a couple of minutes today to rewrite something in my WinPopup Quicksilver Module. It now queries all the WINS servers it can find, instead of just the first one. This is useful when connected to a network containing computers from more than one workgroup.

Here is the new version and the revised source.

By the way - I'm working on something pretty big. It's called oneTunes (until I'll find a better name). It was actually almost done since before I joined the army, but I don't have any time to finish it. It's a program that helps make PCs and Macs use one shared iTunes library, with one copy of the files on one computer, and the ability to import new songs or make changes from every computer connected to it.

Up until now this was not possible - the only existing solutions are: syncing libraries on different computers (you then have more than one copy of your library); doing some hacks to have PCs or Macs use the same library and database file (not possible between a PC and a Mac, because the database format is different); or using the iTunes library sharing (which doesn't let you import new songs, and doesn't act like a native library). I might have forgotten a specific solution, but the point is - there is no existing solution (at least a free one) to have one iTunes library for PCs and Macs.

Cheers,
Tomer

Saturday, September 27, 2008

Merging Messenger History

Well, as you've probably learned from one of my previous posts, I use WLM a lot. After switching back to WLM from Adium after 8 months of usage I've put on my list the task to merge the chat histories of both those programs.

I didn't have a lot of time to do it since I have joined the Army two months ago, but I took this Saturday to finally get it done.

I wrote two scripts:
  • One converts the XML history logs Adium generates to the Messenger Plus! history logs and folder structure
  • The other merges two Messenger Plus! history folder structures into one
I used this to merge it with my 2005-2007 history logs from the old PC as well.

Anyway, links to the scripts are at the end of this post.

You should notice that I use the by-month folder structure and not the by-person one. Also, I use Hebrew locale, so you'll have to change toWeekdayName and toMonthName in convert.py to match your locale.

Have fun and just don't forget to back your files up before you start playing with them!

Tomer


The scripts:

Tuesday, July 22, 2008

WinPopup Quicksilver Module

During the last couple of months I've noticed that a lot of times I had to send URLs, or names of things, or basically - all kinds of strings, to other computers on my network.

This is not about sending stuff to my other computer, for which I have Synergy with it's wonderful clipboard sharing, but to my dad or my brother.

So every time it happened I resorted to e-mail, which was kind of cumbersome (less for me, for I use Quicksilver, but for my brother and dad).

If you haven't heard of, or haven't started using Quicksilver yet, you just don't know what you're missing. It is probably the one best piece of software there is for the Mac (second-best must be TextMate).

Many articles and tutorials have been written about Quicksilver, so I'll just spare it and link to a very good beginner's tutorial, which helped me when I first started using it.

Anyway - I figured one neat way to send those strings to my network neighbors is to use the Messenger Service (WinPopup). For those who aren't familiar with it - do you remember some 4 or 5 years ago, when message boxes with advertisements were popping up every minute or two? That was an abuse of the Messenger Service. It lets you send messages to other computers with the service on.

In Windows those messages are sent with the NET SEND command. Some quick googling revealed how to send them from the Mac (smbclient -M target_name [-U source_name]) and how to get a list of the WINS host names in your workgroup (nmblookup -R -M -- - to get the IP of the WINS server, and then smbclient -U% -L to get the list of clients).

I then sat to write a Quicksilver plugin that would create a catalog of those WINS clients, and allow me to send them Messenger Service messages.

It turns out there is almost no documentation regarding the process of writing Quicksilver plugins. Using the very lacking documentation from Blacktree, the most-useful documentation from a guy named Ankur - Parts 1, 2 and 3, and by looking at what happens in the File Tagging Module, I wrote my WinPopup Service Module.

The module itself is available for download here, and so is the source.
There is a new version available here.

Have fun,
Tomer

P.S. Don't forget to turn on the Messenger Service on your PCs, and make sure they're all in the same workgroup and so is your Mac.

Tuesday, July 8, 2008

Proximity

When I've got my MacBook sometime last December, I was astounded by the hacking possibilities that were then available to me, as it was the first computer I had with Bluetooth, WiFi and such.

Within the first few hours - after I set my phone to synchronize with iCal and iCal with Google Calendar, I figured that I had to find a way to make it happen automatically.

Thanks to Google, I quickly found this great post that helped me make it happen, using a really good program called Proximity.

I later found another wonderful program called MarcoPolo, and used it to switch the scripts for Proximity when I get in or out of my home wireless network range. MarcoPolo can actually handle Bluetooth proximity detection itself, but I remember I had some problems having it run different scripts for Bluetooth discovery/non-discovery depending on whether I was home or not.

Anyway, since I'm kind of impatient, and since I also used the cool idea from the aforementioned post to have Proximity start or stop the screensaver when I go away or come back - I made it check for the presence of my phone every 10 seconds. A successful check takes about 3 seconds, and an unsuccessful check takes about 7 or 8, so you can't get much lower than that.

After a long time of usage, though, I started to get annoyed by the fact that the UI of Proximity became unresponsive during the proximity checks. If I wanted to close it for some reason, it would become a pain in the ass because 8 out of 10 seconds it would give me the wheel of death, and I'd have to wait about half a minute until I got to the quit button and it responded (or resort to killing it from the terminal, which usually happened first).

Also - out of the blue it started making my phone light up and show messages that the computer was connecting and disconnecting every half a minute, which was kind of distracting and annoying.

Thankfully, Denver Timothy - the Proximity guy - is a great internet citizen, and decided to release the source code for Proximity along with the application itself.

Fixing the phone lighting up was pretty straightforward: previously, Proximity would try and connect to the phone and then disconnect, in order to check if it's around. It turns out, though, that there's a much more silent way to do this (somewhat like TCP SYN port scanning compared to the connect() method, only you don't have to be root).

The Cocoa Bluetooth Framework (I have to say I was very impressed with the extensiveness of the Cocoa libraries, as I had no previous experience with Cocoa or Obj-C) has a method called remoteNameRequest which - simply enough - asks for the name of the requested device, which cannot answer if it isn't there. Turns out that was enough to make my phone stop flashing at night.

Now to the UI unresponsiveness - after some research about how threads, memory management, run loops and thread synchronization go around in Cocoa, I gave the job of doing the blocking-proximity-check to a different thread. There was some message-passing to be done between the threads, in order to support different timer intervals for error-checking and normal-checking, but it worked out eventually.

Denver kindly agreed that I post this new version of Proximity for others to use, and even apply these code changes to the trunk.

So here is the application and here is the code.

Have fun,
Tomer

Edit: after a few weeks of usage, I noticed Proximity was crashing once in a while. Turns out the Bluetooth stack implementation in OS X was not thread safe :)
Anyway, I hope the code will help anyone with anything.

Wednesday, July 2, 2008

Integrating Windows Live Messenger With Mac OS X

Everyone who's tried to find a decent MSN Messenger client for the Mac knows it's no easy task. There are a number of contenders: Adium, aMSN, Fire, Mercury Messenger, Proteus, and of course - Microsoft Messenger for the Mac. No client is perfect. Actually - most are terrible (if you ask for a decent interface at least). Adium and Proteus are good but both use libpurple. libpurple is a great library although sadly enough it still doesn't cut with personal messages, voice clips, AV conversations and handwriting for MSNP.

After Adium started giving me loads of disconnection errors lately (which stopped after recompiling with an older version of libpurple, but then started again), and after upgrading the RAM on my MacBook to 4GB - I decided I can now keep VMWare on all day long in Unity Mode and just use the original client.

I love my Mac, but there are still some programs with no equivalent in the Mac world. One is WLM, for the reasons I counted, and some more are Microsoft Office and Subtitle Workshop (if anyone finds a decent alternative, please let me know!). Internet Explorer used to be on that list as well - for using older websites that don't work with Firefox, but with today's Greasemonkey scripts - almost everything works.

Anyway - to business: after a few days of use I found that my solution has a serious flaw. When someone sends you a message on Windows, the conversation window appears minimized on the taskbar and blinks until you've opened it. In Unity Mode, with the taskbar hidden (it looks just awful when it is not), you cannot see if someone sent you a new message, and you also can't see if someone with a hidden or minimized conversation window has sent another message.

The first problem (minimized new conversation windows) was easy to solve: you just need to write a Messenger Plus! script to shoot up on the event of conversation window creation and send a message to that HWND to restore from the taskbar.

For those who aren't familiar - Messenger Plus! is a wonderful addon (along with the mess.be patch) to MSN (now Windows Live) Messenger. It adds a lot of great functionality, including the long-anticipated tabbed chat windows (which sadly enough do not work well in Unity Mode - they leave tracing borders and background when moved around) and a whole-lot-better logging system. Messenger Plus! let's you enhance it even more by writing JScript scripts that perform all kinds of stuff.

Anyway - so now new conversation windows were popping up with new messages and all. I'd prefer them to silently appear minimized on the Dock, but I could not think of a better approach than restoring-and-then-minimizing, which keeps the annoying effect.

I gave it another day to see if I could cope with the second problem of no-notification-on-new-message. Very quickly I found out that - no. If you tend to do other things while IM-ing, you'll quickly leave people hanging for half-an-hour because you started doing other things and forgot.

I decided the best way to keep track of new messages is Growl notifications. I'd have to write another MSNP! script that will send Growl notifications upon new messages arrival. A little Googling revealed that Growl already has networking capabilities over TCP or UDP with their own protocol. After some trial and error with the Terminal I figured out that the network notifications protocol did not by any means support custom application icons. And that generic network-notification icon did not shine.

So - I wrote a Python SOAP server that sat on the Mac side, and recieved notifications from a Python client on the Windows side (which included a title, a message and a Base-64 encoded PNG icon) forwarding them to Growl itself, using their command-line utility. No authentication and encryption were used because the SOAP library I found did not support any HTTP authentication schemes. If someone would like to convert the server to use a different library and incorporate Basic authentication or something, I'll be more than glad.

Anyway - the last brick was the MSNP! script which listens to new message events and calls the client Python script with the contact name, shortened message and the file name of the contact image. A little problem I ran into was converting the Windows Hebrew encoding (cp1255) to UTF-8 for the SOAP request. It turned out to be a matter of adding another parameter to the unicode() method, but I couldn't find it documented anywhere.

Out of there, everything was working great. People were messaging and the notifications were showing, up until some girl with a '<3' in her nickname decided to send a message and then I found out I've forgotten to escape the XML-important characters (and quotes - which caused another problem when passing the message across command-line calls).

So that is it. Here's a screenshot showing how it looks:



Here are the links to the Python server and client (the client is included in the relevant MSNP! script as well), the launch-daemon plist file for the server (which goes into ~/Library/LaunchAgents/), the MSNP! script for the Growl notifications, and the MSNP! script for the automatic restoring.
A zip of all the files is also available here.

I hope someone else out there who is pissed because of the lack of a decent Messenger client for the mac will be able to put this code into good use!


Notes:

1. You need to install Python on your virtual Windows machine.

2. If you use a different windows character encoding than I, you can look for it here and replace the instances of cp1255 in the client script with it.

3. I did not use relative paths in the code, because I was not familiar with which is the current-working-directory when launching Python scripts with launchctl and such, so the paths you may have to change in the code are:
  • The growlnotify tool - it comes in the DMG with Growl, and lets you send notifications from the command-line. You should put it in /usr/local/bin/ or change the path in the server code to where it is.
  • As an alternative icon (if none was sent from the client) I've decided to use the icon for the Microsoft Messenger for the Mac. I will not include it here because it is probably under copyrights and such, but for you personal use I think you can copy it (Cmd+I on the application; click the icon; Cmd+C), create a new image from clipboard (Cmd+N) in Preview, and save it as a PNG somewhere. You should then change the /Users/tomer/Development/MessengerGrowl/Notifier/msn-icon.png path in the server code to yours.
  • The Growl MSNP! script assumes MSNP! is installed in C:\Program Files\Messenger Plus! Live. If you have it installed in a different location you'll have to open up the Growl Notifier.js file from Scripts\Growl Notifier down the MSNP! directory and change the path to the client.py on line 21.
  • Also, the Growl MSNP! script assumes Python is installed in C:\Python25. If it is installed elsewhere, you'll have to change the path to the Python executable in the JScript file (same place as the last one - only line 22).
  • You have to change the path in the launch-daemon plist file to where you placed your server script
4. I told Growl to require a password for networked-notifications. The password is set in the server script in line 31. You can also set it to an empty string if you've set Growl not to ask for a password.

5. The server.py and client.py contain the local IP address of the Mac network interface (and VMWare's network device must be set as Bridged and not NAT, too). In my case it was 192.168.1.12, and you should change it to your static or statically-leased IP address.

6. The server script uses the SOAPPy lib, so you'll have use MacPorts (port install py-soappy) to get it and all it's dependencies. I can't remember, but I don't think there were any other dependencies. If you'll run into any problems, please let me know and I'll look it up.

7. As the current port for SOAPPy is only for Python 2.4, the server script's shebang is followed by /opt/local/bin/python2.4. If you've installed your MacPorts elsewhere, or you are using SOAPPy with a later version of Python, you'll probably want to change that.


Cheers,
Tomer