Saturday, March 23, 2013
Reduce display brightness and volume by quarter notches on Mac
Sometimes you'd be listening to something on your mac with a volume that corresponds to last bar. Then pressing the volume down for one more time would mute it. But one'd wish that there was something else one could have done to bring it to little less than how it was before but not mute it. Here is the solution:
option + shift + brightness buttons
option + shift + volume buttons
Pressing brightness or volume up/down buttons while holding option and shift down would increase/lower the brightness or volume by quarter notches and there by gives you greater control.
Wednesday, March 20, 2013
Fell in love with this Korean song
My daughter loves to watch "Mator tall tales" on Netflix. I watch it too sitting next to her and I love it. Anyway, one thing that caught my attention is the song that comes at the end of it. First I thought it was a Japanese song and later realized it was Korean and the woman's voice pretty much haunted me until I went and found it on youtube. Looks like whoever posted this video had the same love for it. Here is the song in case you'd like to listen to:
Friday, January 18, 2013
AppleScript to open any web interface/account like GMail, etc
Few years back I switched to Mac and since then I'd say it's been great. Yes, Macs are expensive but they do offer great things in comparison. Anyway, since I'm not doing a sales pitch here I'll go ahead and say how you can automate logging onto any of your web accounts, for example your gmail account. The reason I do this is that I open Google web interface for both email and calendar everyday early in the morning at my work. Eventually, you'd think of doing it with just one click and so I came up with this.
First, open AppleScript editor on your mac and type what I show here below:
Of course, you can test this script immediately without having to save it by clicking on "Run" in the AppleScript menu. Once your'e satisfied save it as an application by choosing "Application" from the dropdown menu for File Format. You can drag the saved application onto your dock. Clicking it would take you to gmail web interface with just one and only one click. Nice! Right?
Now, remember that once you save it as an app you wouldn't be able to change the code anymore. If you'd like to see or change the code you'll have to save it in Script format by choosing "Script" for File Format which is default. Again, it's a no brainer doing something like this because you've your password exposed. Whereas saving it as an app doesn't expose anything.
Doing this way you can automate logging onto any web interface with just one click there by avoiding typing the web page address, entering the username, password and then entering return.
Finally, as you see I put "delay 5" in the code so that it waits for 5 seconds before trying to enter the username. The reason is that sometimes a page takes 2 to 3 seconds to load. If it takes more than 5 seconds then change this number. Otherwise, nothing happens as applescript goes through the code executing each line. Which means it'll have entered the username and password into something as the page hasn't loaded yet. In the worst case this might end up typing full or partial username and password into the address bar. So, be careful.
First, open AppleScript editor on your mac and type what I show here below:
tell application "Safari" to open location "https://mail.google.com" delay 5 tell application "Safari" to activate tell application "System Events" keystroke "username" keystroke tab keystroke "password" keystroke return end tellMost of the times usernames and passwords are contain numerals. Entering keystroke "Sreedhar123" for username would just enter "Sreedhar" in the username field without 123 at the end of it. Which I'd say is a problemo. To avoid this from happening we need to enter applescript key codes for the numbers. So, for "Sreedhar123" you need to put this code:
tell application "Safari" to open location "https://mail.google.com"
delay 5
tell application "Safari" to activate
tell application "System Events"
keystroke "Sreedhar"
key code 18
key code 19
key code 20
keystroke tab
keystroke "password"
keystroke return
end tell
Remember that same goes for password as well. Google "applescript keycodes" if you are looking a keycode for a specific character.Of course, you can test this script immediately without having to save it by clicking on "Run" in the AppleScript menu. Once your'e satisfied save it as an application by choosing "Application" from the dropdown menu for File Format. You can drag the saved application onto your dock. Clicking it would take you to gmail web interface with just one and only one click. Nice! Right?
Now, remember that once you save it as an app you wouldn't be able to change the code anymore. If you'd like to see or change the code you'll have to save it in Script format by choosing "Script" for File Format which is default. Again, it's a no brainer doing something like this because you've your password exposed. Whereas saving it as an app doesn't expose anything.
Doing this way you can automate logging onto any web interface with just one click there by avoiding typing the web page address, entering the username, password and then entering return.
Finally, as you see I put "delay 5" in the code so that it waits for 5 seconds before trying to enter the username. The reason is that sometimes a page takes 2 to 3 seconds to load. If it takes more than 5 seconds then change this number. Otherwise, nothing happens as applescript goes through the code executing each line. Which means it'll have entered the username and password into something as the page hasn't loaded yet. In the worst case this might end up typing full or partial username and password into the address bar. So, be careful.
Wednesday, January 16, 2013
Making an app with an applescript on your mac that gets you public transit directions
At the end of the day in my office, just before leaving the office I generally check google maps for getting public transit directions and time tables. Google Maps lets you save driving directions with a link "Save to My Maps" under the directions to your "My places". But this is not the case with public transit directions. Which in my opinion sucks. This might sound trivial to some one who uses their car to goto office. Trust me it's a heck of nuisance to someone like me as I use public transit all the time.
Generally, what I do is I open a new tab in my browser and then open the page "maps.google.com" and then click on public transit, then type the addresses, let's say for example home or office if you've saved them or type the entire addresses and then select the train or bus from options based on your public transit mode. Again, it doesn't sound that big of a deal if you have to do this once in a month. But I do this million times in a month. So, I've started looking for some sort of a way to save it to my places.
Whatever I found googling didn't help me at all. In the end I've decided to make an app for my self with an applescript on my mac. Then I thought of putting it here if someone is interested in knowing how I did it. Here we go:
First goto maps.google.com and get the public transit directions for your destination. Let's say we need public transit directions from Hoboken HBLR Terminal to Penn Station, New York, NY. I know that there is a PATH train service that runs from Hoboken to 34th street which is where Penn station. Of course, you don't need to know anything of this at all. As I know I always select the option "train" from show options. Then I get the link to directions from share symbol next to My places. This is what I've got here:
https://maps.google.com/maps?saddr=Hoboken+HBLR+Terminal&daddr=Penn+Station,+New+York,+NY&hl=en&ll=40.740982,-74.011202&spn=0.027411,0.05579&sll=40.740982,-74.012575&sspn=0.027411,0.05579&geocode=Fc-MbQId92SW-yk7lmyP4lnCiTHoGLLYwLjysQ%3BFfTNbQIdlPKW-yELxignjABkPin5tzQUrlnCiTELxignjABkPg&oq=Penn&dirflg=rT&ttype=now&noexp=0&noal=0&sort=def&mra=ls&t=m&z=15&start=0
Once you have this link, go and open applescript editor (Press command + space bar and type applescript) and add this code below and then save it to where ever you want to have it in your system. I put it on my desktop.
Applescript Code:
do shell script "open -a Safari \"https://maps.google.com/maps?saddr=Hoboken+HBLR+Terminal&daddr=Penn+Station,+New+York,+NY&hl=en&ll=40.740982,-74.011202&spn=0.027411,0.05579&sll=40.740982,-74.012575&sspn=0.027411,0.05579&geocode=Fc-MbQId92SW-yk7lmyP4lnCiTHoGLLYwLjysQ%3BFfTNbQIdlPKW-yELxignjABkPin5tzQUrlnCiTELxignjABkPg&oq=Penn&dirflg=rT&ttype=now&noexp=0&noal=0&sort=def&mra=ls&t=m&z=15&start=0\""
The above code opens the tab with public transit directions in Safari.
To open the page in a default browser, just remove -a Safari:
do shell script "open \"https://maps.google.com/maps?saddr=Hoboken+HBLR+Terminal&daddr=Penn+Station,+New+York,+NY&hl=en&ll=40.740982,-74.011202&spn=0.027411,0.05579&sll=40.740982,-74.012575&sspn=0.027411,0.05579&geocode=Fc-MbQId92SW-yk7lmyP4lnCiTHoGLLYwLjysQ%3BFfTNbQIdlPKW-yELxignjABkPin5tzQUrlnCiTELxignjABkPg&oq=Penn&dirflg=rT&ttype=now&noexp=0&noal=0&sort=def&mra=ls&t=m&z=15&start=0\""
Before making it an app you can simply try running it with "Run" on the editor which shows you whether it is working or not. Once you know that it is working the way you wanted it to be go for save options and there select "Application" in the "File Format" drop down menu. Once you save it as application, let's say on your Desktop you can simply drag it onto your Dock.
Once you have it there on the dock you can simply click it just like you open any other application. This opens public transit directions with your selected public transportation mode with the latest time table.
By the way, if you'd like to save your script so that you can modify or refer to in the future then I say save another copy some where in SCPT format by choosing SCPT from File Format drop down menu options.
Saturday, August 27, 2011
MySQL with ODBC driver
Configuring MySQL and ODBC driver
# more /etc/odbcinst.ini # Example driver definitinions # # # Included in the unixODBC package [PostgreSQL] Description = ODBC for PostgreSQL Driver = /usr/lib64/libodbcpsql.so Setup = /usr/lib64/libodbcpsqlS.so FileUsage = 1 # Driver from the MyODBC package # Setup from the unixODBC package [MySQL] Description = ODBC for MySQL Driver = /usr/lib64/libmyodbc3.so Setup = /usr/lib64/libodbcmyS.so FileUsage = 1
/etc/odbc.ini
# more /etc/odbc.ini [ODBC] Description = Moab MySQL Database Driver = MySQL USER = root PASSWORD = <write sql root password here> Server = localhost Database = Moab Port = 3306 Socket = /var/lib/mysql/mysql.sock Option = Stmt =The above standard odbc driver file syntax should be used to configure how your application talks to MySQL. Which means the file will have the same content as /etc/odbc.ini. For example application moab uses the file dsninfo.dsn in /opt/moab directory.
# more /opt/moab/dsninfo.dsn [ODBC] Driver = MySQL USER = root PASSWORD = <write sql password here> Server = localhost Database = Moab Port = 3306 Socket = /var/lib/mysql/mysql.sock Option = Stmt =
Testing
Test the ODBC to MySQL connection by running the isql command, which reads the /etc/odbc.ini file:# isql -v ODBC +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ Segmentation fault
Solution
To get rid of the error "segmentation fault" we need to recompile and install the unixODBC with an extra configure options.Installing unixODBC
Web link: http://www.unixodbc.org/# wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.0.tar.gz # tar xzvf unixODBC-2.3.0.tar.gz # cd unixODBC-2.3.0 # ./configure --enable-stats=no --enable-gui=no --sysconfdir=/etc --prefix=/usr # make # make install--enable-stats=no is an attempt to correct the segmentation fault.
--enable-gui=no provides no GUIs, is used when ./configure can't find the X includes.
Installing ODBC Driver: MyODBC
Web link: http://www.mysql.com/products/connector/Web link: http://www.mysql.com/downloads/connector/odbc/
# rpm -ivh --nodeps MyODBC-3.51.07-1.i586.rpm--nodeps avoids aborting because rpm can't find libmyodbc that does exist in /usr/lib.
When isql won't work because it can't find the library, go make a link in /usr/lib to libmyodbc3-3.51.07.so and name it libmyodbc.so.
Testing
Test the ODBC to MySQL connection by running the isql command, which reads the /etc/odbc.ini file:# isql -v ODBC +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ sreeSQL> show tables +-----------------------------------------------------------------+ | Tables_in_Moab | +-----------------------------------------------------------------+ | EventType | | Events | | GeneralStats | | GenericMetrics | | Jobs | | Moab | | NodeStats | | NodeStatsGenericResources | | Nodes | | ObjectType | | Requests | | mcheckpoint | +-----------------------------------------------------------------+ SQLRowCount returns -4294967284 12 rows fetched SQL> quit [root@cuda unixODBC-2.3.0]#
Thursday, August 25, 2011
Applescript for Apple Mail
Almost 6 months back I encountered a problem with desktop mail client on Mac. I had to use Applescript to solve the problem. I always wanted to copy whatever email I get onto my mac. I setup rules to copy certain emails based on specific criteria on my mac. The problem was whenever I read an email it was still unread on my mac. I tried every other method to make their status read. Nothing worked and so finally I opted for Applescript. You can see that the number of unread mail count on my mac is 716 while inbox has zero.
I wrote this applescript to solve this problem. Here it is:
It doesn't change the status of new emails in your inbox. It only changes the status of emails on your mac. Once you run the script in applescript editor you can see the count dropping down to zero very quickly.
The good thing with the script is you can make this run at specific times in a day by using ical. Just use alarm options in iCal to setup to run this script at certain of the day. I run this script at 8am early in the morning and at noon and at 4 pm, etc so that I don't see the annoying email count on my mac.
I wrote this applescript to solve this problem. Here it is:
tell application "Mail" set theMailboxes to every mailbox repeat with theMailbox in theMailboxes set theMessages to every message of theMailbox repeat with theMessage in theMessages if read status of theMessage is false then set read status of theMessage to true end if end repeat end repeat end tell
It doesn't change the status of new emails in your inbox. It only changes the status of emails on your mac. Once you run the script in applescript editor you can see the count dropping down to zero very quickly.
The good thing with the script is you can make this run at specific times in a day by using ical. Just use alarm options in iCal to setup to run this script at certain of the day. I run this script at 8am early in the morning and at noon and at 4 pm, etc so that I don't see the annoying email count on my mac.
Wednesday, August 24, 2011
Locking screen on Mac from Terminal
I do all my work from a terminal on my mac. I try to use as much keyboard as possible for everything. Whenever I need to lock my screen which I say many times in a day I either use hot corners or key chain options. Then I thought why not from terminal it self. In case you are also interested to know how to do this, here is how I did it.
Open up a terminal and do these commands. The last command "schlock" will lock the screen whenever you execute it from the terminal. Of course, you can give what ever name you like. Make sure that it doesn't have space between the words, for example "screen lock". You can always give something like "screen_lock", etc.
Open up a terminal and do these commands. The last command "schlock" will lock the screen whenever you execute it from the terminal. Of course, you can give what ever name you like. Make sure that it doesn't have space between the words, for example "screen lock". You can always give something like "screen_lock", etc.
$ echo "alias scrlock='/System/Library/CoreServices/\"Menu Extras\"/\ User.menu/Contents/Resources/CGSession -suspend'" >> ~/.bashrc $ source ~/.bashrc $ scrlock
Subscribe to:
Posts (Atom)
PBS Script Generator: Interdependent dropdown/select menus in Javascript
About Me
- My Knotty Mind - Labyrinth
- LA, CA, United States
- Here I write about the battles that have been going on in my mind. It's pretty much a scribble.

