Monday, October 17, 2011

Use Automator to play song everyday morning

I wake up everyday to alarm sound that's pretty boring. Well I could download an interesting sound and have it as alarm sound. I was wondering if there is a way to fire up a job on my new mac. I searched online and found a very nice way to do it. Mac has a tool called "Automator". If you can't find where it is, just use search on the right top corner. I wanted to play "Suprabhatam" everyday morning as my alarm sound. I found a youtube video that has it. I am not very good at scripting (to be honest I dont know anything on Mac). So I used Automator to create a workflow. Here are the steps:
- Open Automator
- From the library, choose Internet
- Get specified URL. This would just get data from the URL and not really open it.
- Specify the URL you want , which is the video link to youtube.
- Click "Display URL" from the options tab. This would open the URL
- Save the workflow

This creates a workflow item that you can click and it would open youtube with the video you specified. Now, we need to find a way to fire it up everyday. iCal with the ability to have a repeat schedule comes handy for that. Here is how you do it:
- open iCal
- schedule a meeting/action at the time you want the video to be played
- chose alarm type to "open file"
- chose the workflow file you created

Thats it. The iCal will fire up the file everyday at the same time and the youtube file will be played. I love it now. I wake up to "Suprabhatam" everyday.
Do let me know if there is a simpler way to do the same, I am interested to know.

Tuesday, October 11, 2011

Using VNC on Mac

Recently I switched my jobs and was given a MacBookPro and a kick-ass ASUS 6-core intel i7 desktop. (sabertooth x58 motherboard). The desktop is so damn powerful that i want to make this the main work PC. The problem so far is, that the email is on Mac and hence the pointers to the documents and all. I dont want to switch between the two PCs (switch keyboards, mouse etc). So I thought why not create remote desktop environment for both.
With that I was easily able to create remote desktop from Mac to PC. Just download the remote desktop software for Mac from Microsoft website and you are pretty much good to go. Make sure you enable remote desktop on the PC. It was straight forward after that.
The other way round was more tedious. First, there is no software that allows remote desktop from Windows to Mac. There is a new company that seems to be still working on that but is not yet ready. I inquired around and no one in my company has done that earlier. The closest that they did is to use VNC. So I decided to give it a try.
Here is the procedure:

  • on Mac, go to "system preferences"
  • Click "sharing"
  • enable the "screen sharing" by checking the box next to it
  • click the "computer settings" and chose a good password to be used by the users who connect via VNC
  • note down the ip address shown in the "screen sharing" pop up
  • go to PC and open your vnc viewer (I used RealVNC client, download from here if you dont have it)
  • When the viewer opens up, click the "options" and chose "color level" as full ; otherwise vnc exits after connecting.
  • enter the server ip address and click ok
  • enter the password you gave on Mac to let the PC connect to Mac
  • At this point you should see what is on Mac on your PC
I hope this is helpful for folks who are new to Mac as I am. I struggled about 2 hours to get a good PC to Mac set up going. The only problem I am encountering now is that the VNC seems to disconnect every so often. Other than that I am harnessing the power to two great machines.




Improved version of mailing from command line using ruby


After I wrote my first mail program, I was not happy with sticking in the recepient's email addr and message in the program. So I modified the program to take recepient's address and the message from command line. The message is terminated by entering a new line with just period (.).
#The following program has been tested with Ruby1.9.1
# Used my Gmail Acct. If not SMTP settings need to change
require 'net/smtp'

puts "Enter the recepient's email id";
toaddr = gets.chomp
puts "Enter message (To terminate enter a new line with .)"
msg = "";
line = gets
until line.chomp.eql? "."
 msg << line;
 line = gets
end

smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls

smtp.start(Socket.gethostname,'username','password',:login) do |server|
   smtp.send_message msg, 'fromaddr',toaddr
end

Have fun using it.

Mail from command line using ruby


I always wanted to send a simple mail, like a one liner, to someone but felt it was inefficient to open the email editor, type in everything. So I started off writing a simple script that I can use from command line to kick off the mail to someone.
First since I started reading about Ruby and its powerfulness, thought it would be best to start the script in Ruby. So, I searched internet to find the solutions.
Here is the first solution I found. The first solution mentioned in that link didnt work for me for the same exact reasons those folks mentioned. I had 1.8.6 version of Ruby. I upgraded it to Ruby 1.9.0. Even then it didnt work. It kept giving :
"mail.rb:2:in `require': no such file to load -- smtp_tls (LoadError)  from mail.rb:2:in `
'"

mail.rb being my test program.
After a bit of fiddling with it, i went back to google to try the search. This time I found another thread where they discussed this a little more. Anyway, the issue is 1.9.0doesnt need require  'smtp_tls' statement.


Here is the complete program : I am assuming gmail as the server


require 'net/smtp'

msgstr = "Some msg"

smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls

smtp.start(Socket.gethostname,'username','password',:login) do |server|
   smtp.send_message msgstr, 'from', 'to'
end



Hope you like the program