Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A simple 'graphical' calculator script for Terminal UNIX
It has always annoyed me that a simple calculator would take several seconds to load on my current machine, and yet MacOS Classic's calculator is instantaneous even on my 33mhz 68k Mac. xcalc is also instantaneous, but requires x11 to load, which takes a while.

As I'm always running Terminal.app anyway, I thought a terminal calculator with a 'GUI' would be nice. After googling for it with no luck, I decided to write a shell script that mimics the behavior of a simple calculator. It loads instantly even on a iMac 233, although screen redraw can be a little sluggish on such hardware.

Here's what it looks like, and the result of your calculation is copied to the clipboard.

I'm not a developer in any way, so the code is probably the ugliest thing ever written, but it works for me. It handles only the basic 4 operations with 5 decimal cases. type 'q' to quit, the rest should be self explainable. Improvements are more than welcome -- for example, I couldn't map the clear key in the numeric pad, so I used 'c' for clear.

[robg adds: I mirrored the script here on hints. Remember to make it executable first (chmod a+x tcalc). I tested it, it seems to work well, and it is indeed speedy.]
    •    
  • Currently 2.25 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[12,561 views]  

A simple 'graphical' calculator script for Terminal | 18 comments | Create New Account
Click here to return to the 'A simple 'graphical' calculator script for Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
How about using the Dashboard Calc Widget ?
Authored by: alexmathew on Mar 13, '06 08:15:38AM

Its pretty fast and just takes a button (F12) press?



[ Reply to This | # ]
How about using the Dashboard Calc Widget ?
Authored by: Pedro Estarque on Mar 13, '06 08:48:50AM

Dashboard is a huge memory hog, and the script loads much faster than the Widget in my machine. I'm sure anyone with G5 ( or Intel's Core) must have just about any small app loading instantly, but that's not the case with older hardware.
Besides, it's got the geek factor to it :)



[ Reply to This | # ]
Dashboad Kickstart
Authored by: alexmathew on Mar 14, '06 11:00:03AM

If your Widgets are loading slowly try this:
http://www.alwintroost.nl/content/widgets/dashboardkickstart.xml

I'm on a PB G4 1.5GHZ and F12 gets me my Dashboard almost instantaneously.
Yes, the Widgets do take Real Memory (about 20MB per Widget) but with 1GB of RAM, I can afford it.

I like the script, but just wanted to remind people abou the Widget too.
Thanks
AM



[ Reply to This | # ]
How about using the Dashboard Calc Widget ?
Authored by: Glide on Mar 13, '06 09:04:03AM

If you want something even quicker you can always use the already supplied /usr/bin/bc instead. Or if you really really want to you can download wcalc (both gui and cli) http://w-calc.sourceforge.net/download.php but then neither bc nor wcalc look as pretty in the shell.

I seem to recall years ago using another ncurses based graphical calc on the cmd line but for the life of me can't remember what it was.

Great script BTW.

---

- Jase



[ Reply to This | # ]
A simple 'graphical' caculator script for Terminal
Authored by: dal20402 on Mar 13, '06 08:56:32AM

If the calculator takes several seconds to load, something may be broken... well under 1 sec. for me, and my hardware isn't cutting-edge (1.5GHz PB G4, 5400 rpm disk, 1.25 GB RAM).

I like the geek factor of the script but in "real life" it seems like too much effort.



[ Reply to This | # ]
A simple 'graphical' caculator script for Terminal
Authored by: vonleigh on Mar 14, '06 02:10:49AM

You have the last or next to last revision of the PB G4 with over a gig of ram, that's a very decent rig (a year old or less). If you can change machines every year, yes you are in fact the cutting edge. There are many G3 iMacs, iBooks and even older PowerBooks (think pre-titanium) still in use.

These machines can be coerced into running Tiger (some not officially, only up to Panther), to be used for email/web/music/dvd/word processing.

Ya it's slow (by our standards), but it works, it's solid, and chances are the hardware is free or close to it.

vonleigh



[ Reply to This | # ]
A simple 'graphical' caculator script for Terminal
Authored by: dave1212 on Mar 14, '06 05:59:11PM

Dual 450, 2 GB RAM, 10.4.4 Calculator is near-instant (I launch it with a key command set through Butler)

Nice to have options, and always nice to see someone contributing their code for us code n00bs.



[ Reply to This | # ]
A simple 'graphical' caculator script for Terminal
Authored by: kbradnam on Mar 13, '06 09:11:45AM

Command line calculators (albeit non-graphical versions) have also been raised in this hint:

http://www.macosxhints.com/article.php?story=20050131140857217



[ Reply to This | # ]
A simple 'graphical' calculator script for Terminal
Authored by: rspress on Mar 13, '06 09:50:08AM

If you are not running the terminal already then launching the terminal to use the calculator takes the same time, about 2 seconds on my 800mhz eMac, as the calculator.

Still this is a useful little puppy to have around so I added to my usr/local/bin folder.

I should mention one thing. I wish the hints would add a little more information about what you have to do to get this working under UNIX. While I knew what to do and where to put things there are plenty of OS X users are interested in using UNIX under OS X but have been put off by the lack of instructions or good documentation. While I am not saying we should hold their hands and do all the work for them we could at least give them a push in the right direction and spur their interest in using UNIX.



[ Reply to This | # ]
A simple 'graphical' calculator script for Terminal
Authored by: xSmurf on Mar 13, '06 11:50:51AM

That would probably explain why macosxhints has published, a few times in the past iirc, guides to the Terminal basics ;)

---
PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf



[ Reply to This | # ]
I like Calq
Authored by: jecwobble on Mar 13, '06 11:59:21AM
Just my two cents worth, but even with Terminal running, you have to start the script by typing. I have Calq set to launch with F8. Simple and fast.

[ Reply to This | # ]
I like Calq
Authored by: unixgold on Mar 16, '06 12:38:51PM

That website doesn't seem to work :\ Any other place to grab it?



[ Reply to This | # ]
A simple 'graphical' calculator script for Terminal
Authored by: z5h on Mar 13, '06 12:10:07PM

What's wrong with bc?



[ Reply to This | # ]
and whats wrong with calcservice?
Authored by: nick on Mar 13, '06 12:23:36PM

.



[ Reply to This | # ]
Or vc.pl
Authored by: LoB on Mar 14, '06 12:46:12AM
vc.pl if you like RPN calculators...

[ Reply to This | # ]
A simple 'graphical' calculator script for Terminal
Authored by: matxey on Mar 13, '06 03:18:19PM

Remove any options under the "Speech" menu, this is usually a culprit. Mine takes two bounces/seconds to startup on 1Ghz TiBook, faster than the Terminal.



[ Reply to This | # ]
A simple 'graphical' calculator script for Terminal
Authored by: Peganthyrus on Mar 14, '06 07:24:51AM

I use Quicksilver for a lot of my quick calculation needs.

apple apple space 2+2 tab calc return ...and a bezel with "4" in it fills the whole screen.

You have to have installed the "Calculator Action" plugin.



[ Reply to This | # ]
A simple 'graphical' calculator script for Terminal
Authored by: mikebremford on Mar 16, '06 02:47:18AM
I knocked up a tcsh alias years ago so I could do "calc (5*3)+2" from the command line - for those running csh, try:
alias calc 'echo "scale=4; \!*" | bc | sed "s/^\(-\)*\./\10./"'
However recently I switched to zsh, so wrote the following which is the equivalent. The alias-to-a-function is so I can get the noglob in there, which is necessary to use '*' from the command line:
alias calc="noglob __calc"
__calc() {
    echo "scale=4; $*" | bc | sed "s/^\(-\)?\./\10./"
}
It's not graphical but if you're in a terminal, who cares?

[ Reply to This | # ]