For many years I've used the Lloydslounge 'Gee!' utility that was part
of my Finder's menu-bar near the right-end. It worked fine --- until
Yosemite came along. I get enough emails that I decided to try and
tackle the job of writing a replacement, completely in bash-scripts,
along with a couple of simple apple-scripts providing Desktop apps
that displayed a dialog box with the info. In order for these scripts
to work with Gmail, you must turn ON the Less secure apps option.
These scripts have been tested on Snow Leopard (10.6.8). Yosemite
(10.10), and Sierra (10.12). They probably work on other Macintosh
operating systems. It might need changes for any other systems.
The 'info' consists of a time-stamp of when my Gmail was interrogated,
and the count of unread emails within my Inbox. The interrogation occurs
under my control using a 'cron' task, and it says the count using 'say'
if being run by 'cron'. The task doesn't say anything if the count is
0, and was 0 at the prior time-stamp.
The tgz-file (attachment) contains the following six (6) items: Four
(4) bash-scripts, that probably should be kept in your $HOME location.
Your $PATH should include your $HOME as it's last item. Two (2)
apple-scripts that can be stored wherever you want. I have an
'AppleScript' folder where I keep mine. First, download the
attachment.
Installation is simple. Double-click the 'feed.tgz' to extract the
'feed' folder. Open the 'feed' folder, by double-clicking it and then
drag the apple-scripts wherever you want. The remaining four
bash-scripts should go into your $HOME directory.
They are: feed.gen, feed.reset. getfeed, and shofeed.
They should already be executable files, which you can check
with the 'ls -l file' command against each file.
You must now use the Terminal.app to setup your new Gmail-Notifier.
Of course, you need a username and password to access your Gmail.
That's what 'feed.gen' is all about. Navigate to your $HOME directory,
and enter the following command:
./feed.gen username:password
That's a leading dot-slash followed by the script name. The only parm
is your username in Gmail, and its corresponding password, separated
by a colon. This is encrypted and saved in your ~/Library/Preferences
folder. for use by 'getfeed', which actually interrogates your Gmail.
If your username and password are correct, you should be able to get
your fist sample of how this notifier works. Issue this command:
./getfeed
That should return a count of how many unread mssages there are in
your Inbox. If there are no error messages, you can now use 'shofeed'
to see both the time-stamp and count of unread emails.
./shofeed
If there were errors, you'll have to run getfeed again, but tracing it.
bash -x getfeed
That will show you the execution, and you should be able to detect
where it goes wrong. If you're stuck, send me a message at my
Contact link on my Google home page.
If you wish, you can now create the Desktop apps that make it easy for
you to manually check or get your Gmail status. I create the apps using
Automator in the following manner:
Using Terminal, I copy an applesctipt to my clipboard:
pbcopy <getfeed.applescript
Of course you have to do this from within the directory where you placed
the applescript. Once you have it copied, You need to launch Automator
from the Applications directory. I do that with a Finder window. Once
the Automator comes up, you'll see its name replacing Finder in the upper
left of the munu-bar. Next to its name is the 'File' menu. Click that and
choose the 'New' option. That opens a window from which you can select
the 'type for your document', and you want 'Application', so click that and
hit your 'return' key to activate your choice.
You'll get another window that has 'Actions' near the top, with an entry
box above a second column of choices. Start typing 'Run' and you should
get a series of Run-choices. Double-click on 'Run Applescript'. Another
window will open on the right-side with a sample applescript within it.
Click, hold, and drag through all the text from 'on run' through 'end run'.
Once it's all highlighted, cmd-delete to erase it, and then cmd-v to paste
your clipboard data into the window. You now have the applescript you want
to compile in the window. Click the 'hammer' button to compile the script.
Once that's done, click on the 'File' menu again, and choose "save" (cmd-s).
Pick where you want to store the executable application. I typically place
them on my Desktop. You can choose from the left-column. Be sure to
replace the 'Untitled' name at the top by your final 'application.app' name.
You can repeat these step with your 'shofeed.applescript'. You now have
easy to use applications on your Desktop. Just double-click them.
In order for 'getfeed' to monitor your Gmail on a regular basis, you now
need to setup automatic execution of 'getfeed' according to a regular
schedule. I've found the simplest way to do this is with 'cron-jobs', which
are submitted by the 'cron' facility. If you already have a 'crontab' table,
you're already to add some new entries to your table. Otherwise, you'll
be starting fresh by creating your 'crontab' table. Either way, the method
involves the 'ctontab -e' command within Terminal.
A typical cron-job runs with just the following environment variables:
LOGNAME=macname
USER=macname
HOME=/Users/macname
PWD=/Users/macname
PATH=/usr/bin:/bin:$HOME
SHELL=/bin/sh
Notice the PATH is enough to cover executables in your $HOME directory.
That's why it's so important to define your own PATH in your crontab table.
'crontab' needs a text-editor for you to use. You can use any editor you
like, but it's best if you've given 'crontab' a hint by setting up an EDITOR
environment variable than names your editor. 'vi' is used by some, others
like BBEdit. All you need to do in Terminal (using a bash-shell) is this:
or any other editor name. Now you do the following:
which places you in your chosen editor with a copy of your current table.
If you don't have a table, you'll see a message that you need to delete.
Your table should have two parts. The first part is a list of environment
variable settings. These are what I have, and I recommend them to you.
CRONJOB=CRONJOB
MAILTO='username@gmail.com'
REPLYTO='username@gmail.com'
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:.:/Users/macname
The 'username' is your Gmail account name. 'cron' applies these four
settings to every job it runs for you. I use CRONJOB in the 'getfeed' code
to signal that 'getfeed' is being run independently from whatever I'm doing.
That's important because certain things don't function the same way when
being run in the background. 'cron' with run your task, in the background,
according to a schedule, which is the second part of the table. These are
the entries that 'cron' applies any time your computer is 'awake'. 'getfeed'
runs according to the following schedule, for me:
09,29,49 06-23 * * * /Users/macname/getfeed >/dev/null 2>&1 &
That's every day from 6 AM until until midnight, starting at 06:09 every
twenty minutes, i.e. 06:09, 06:29, 06:49, 07:09 ... through 23:49.
After you've completed your table, you SAVE the result, which is ':wq'
for 'vi'. Then quit your editor. 'crontab' reloads your settings for 'cron'.
'getfeed' will now run every twenty minutes your computer is awake,
starting at the next time slot in the table, and quitting when you either
shutdown, or put your computer to sleep. Use your 'shofeed.app' to
see your current Gamil count of unread messages, and the time-stamp
when 'getfeed' last looked.