Archive for the ‘Software’ Category

Growl notifier for mac’s battery status

Tuesday, February 9th, 2010

There have been many times that my macbook’s battery is almost running out and about to die and I don’t pay attention to the icon in my menubar. The warning itself appears only when the battery level is 10% remaining. Recently however, this problem started causing more pain. My battery needs to be replaced, because of which at about 23% the machine will just shutdown. So I wrote a small script that calculates the battery power and along with some launchctl magic and growl, I now get a notification when my batter level is below 30%.

Here is what you need to do. Download growl 1.2 from here and install it. If you are using Adium you will most likely already have growl. To test, run this command in your terminal after you install growl.

growlnotify -m "test message"

The code for getting the battery capacity notification is below

#! /bin/bash
NOTIFICATION_THRESHOLD="30"
#this works only on snow leopard 10.6.
charge=`/usr/sbin/ioreg -l | /usr/bin/grep -i capacity | /usr/bin/tr '\n' ' | ' | /usr/bin/awk '{printf("%.0f",$10/$5 * 100)}'`
if [ $charge -lt $NOTIFICATION_THRESHOLD ]; then
message="Battery power level is $charge%"
/usr/local/bin/growlnotify -t "BatteryNotifier" -s -m "$message"
fi

The full paths are essential for the next step. Save the above in a file, make it executable with ‘chmod +x’ and run. You will not see anything if your battery charge is above 30%. In order to run this as a cronjob or daemon process create a file of type launchd.plist in
~/Library/LaunchAgents/
and give the file a unique name. My file is named com.abuhafsa.BatteryNotifier.plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.abuhafsa.BatteryNotifier</string>
        <key>ProgramArguments</key>
        <array>
                <string>/opt/scripts/daemons/battery_notifier.sh</string>
        </array>
        <key>StartInterval</key>
        <integer>300</integer>
</dict>
</plist>

Remember to change the location of the script to where your file is stored. The ‘StartInterval’ is time in seconds. Change it to whatever you desire and the script will run at that interval. Now logout and log back, which will enable launchctl to add this daemon to its list of tasks.

Typing verses from The Quran

Thursday, January 21st, 2010

You type verses from the Quran all the time, in Arabic? Yes. How about doing it in less than a second? No? Read on then.
What I’m talking about are text expansion softwares. These are small utilities that run in the background and look for what you type. When you type a pre-configured sequence of characters, magic happens. So no matter what application I’m using, as soon as I type the letters ‘w b r’, this utility auto expands right at that place into ‘with best regards’. This is a huge time saver for people who do a lot of typing on their computers. It’s even useful to us software developers. For the code snippets you might need on a regular basis, these utilities can make you more productive.
It’s east to imagine the benefits of this amazing utility. You don’t type often used word or phrases over and over, you save time, type faster etc etc. To me this utility presented another idea. Before I talk about that, let me briefly mention my project so you’ll understand what I’m doing.
As an active seeker of Islamic knowledge I often find the need to include Quranic verses in my notes. The most naive way us to start typing it. It not only is painstakingly slow, you can make mistakes unintentionally. Another and most common way is to copy paste. That too can take some time. Since you have to first search or navigate to the ayah and then copy paste. So to ease this task I came up with the following idea(mind you this is all for mac users. Sorry I don’t develop for windows).

Develop a software utility that is capable of

  1. Being called from anywhere via clicking on its icon in the dock or menu bar icon
  2. Must be launched by a keyboard shortcut
  3. when launched, a search box should appear allowing to search for a verse by
    1. either surah name and verse number
    2. surah number and verse name
    3. if none of the above then at least being able to do a regular search (least desired feature for v 1.0)
  4. Once the software is able to pull up the verse, any one of the following should be possible
    1. copy the verse to the clipboard
    2. paste it into the current cursor position of the application
    3. provide an English or any desired translation of that verse

The above is only a glimpse of my initial thoughts on this project. While I procrastinate ;) on this idea, I wanted something right now. Enter text expander utilities. I realized that I could use one of these tools and get a partial result of what I truly wanted. So I spent a little time working on plugins for both Typinator and TextExpander. Why these two is not the subject here. That I’ll discuss some place else. Take a look at the small video below.

Excited yet? To learn more about how you can do this head on over to my project page.

Twitter plugins for wordpress?

Monday, November 30th, 2009

Does anyone have suggestions on good plugins for wordpress, that can cross link to Twitter? My requirement are:
1. Should be able to post the content of my blog entries as tweets and end with a short url, if the blog post is over 140 chars.
2. Open source and free
3. Clean and simple interface
4. Must be a plugin not widget
5. [optional] Allow for posting tweets to multiple Twitter accounts.

Have something to say? Leave a comment please!

Twitter & WP Integration

Thursday, November 26th, 2009

I am testing a new wordpress plugin that auto tweets my posts. So please bear with me while I try to set this up correctly.

Islamic mac apps

Friday, November 6th, 2009

I got asked the infamous question again, “What Islamic software should I install on the mac?” My theory is, if you get asked more than once, its probably worth putting pen to paper. Err, in this case fingers on the keyboard ;) . Anyways here goes my list of apps.

  1. For Quran I would recommend Zekr. By far, in my opinion, this app beats any other out there. Its open source, free and very highly customizable. I’m thinking of a separate post to cover Zekr but will highlight some key features here. In addition to the standard arabic and translation you will find:
    1. capability to search both in arabic and english
    2. multiple translations in different languages
    3. good for memorization
    4. selection of various reciters and on and on…
  2. As for an app for hadith, I haven’t found one so far.
  3. To keep track of prayer times, I use Guidance. Unlike Zekr, this app has a native feel. It was written specifically for the mac. Again this too is free. It has a lot of options and stays very nicely and quietly in the menubar.
  4. Any serious student of knowledge will have the need to type in arabic. So go ahead and enable that option. It’s all there, nothing to download or install. Go to System Preferences > Language & Text*. If you don’t see عربي, click on ‘edit list’ and add it. Once you finish that go to ‘Input Source’ tab and select the keyboard layout. I use Arabic-QWERTY as its easily maps to the transliterated letter. For example, If I need to type Abu in arabic, I type A B U and get ابو.
  5. Another thing you might want to have when taking notes or just writing, is the ability to quote verses from the Quran. One way is to copy paste from Zekr or some website. But if you do a lot of extensive typing you how much of  a pain it can become. This is where text expansion comes in handy. Text expansion software will auto expand snippets or some sequence of characters into a desired string. So, if I wanted the first verse of Surah Kahf, all I do is type “q18:1″ and  الْحَمْدُ لِلَّهِ الَّذِي أَنْزَلَ عَلَىٰ عَبْدِهِ الْكِتَابَ وَلَمْ يَجْعَلْ لَهُ عِوَجًا ۜ appears in my text.  In order to do this, I have an app called Typinator. Now along with that you will need a bundle for The Quran. I’ve started a project to create bundles for different text expansion software. Leave a comment below if you’d like to download a copy. You can check out my project page at http://github.com/mabdulghani/quran-verse-expander

And that’s about it for my list. If you need any help with the apps above, feel free to contact me.

*this is in Snow leopard(10.6). In Leopard(10.5) or Tiger(10.4) you are looking for ‘International’ in system preferences.