Updated Gmail Macros Script #

As some commenters had noticed, Gmail changed the DOM node ID it uses for the action menu, which broke my Gmail Macros Greasemonkey script (since that's how it dispatches commands to the Gmail UI). I have now updated the script to work with both new and old IDs.

Additionally, based on my experience developing the Google Reader labels selector, I've gotten rid of a harmless exception that would show up when using the label selector in this script (bug 236791 has more details).

Update on 3/25: The script now also recognizes the "Contacts" section as a destination when using the "g" shortcut.

76 Comments

Hi,

I've also noticed that the script gmail-label-colors has some problems. For example, in the "Inbox" view, I am unable to remove a colored label from an item. Please try it to see what happens.

Thanks for these scripts!
I've patched this new version with my extensions and fixed a few bugs.

http://gr.ayre.st/~grayrest/greasemonkey/gmail/gmail-macros.user.js
Bugs with my code, that is.

Thanks for the script mihai! gmail is so much more annoying without it.
Great work on the script mihai and Karl for your great modifications. Any chance allowing g/c to get to contacts. Perhaps i'll just tweak it myself
Karl G, would you be able to check on one more thing with the script? It would be nice if Contacts were selectable with the labelselector as well. Also what tools do you use to figure this stuff out?
Sorry for so many comments. Mihai, would it be possible to add go to contacts to the labelselector? Thanks!
This update seems to have returned the read and archive key to 'P' instead of 'D' which collides with (P)revious. Also, the '?' for help didn't seem to open up.

Am I doing something wrong? I'm no greasemonkey ninja.
Greg, I have updated the script; it should now handle the "Contacts" section too.
I've updated my version (you see, I'm quite lazy, I just let mihai do all the work). :]

Greg:

As to what you use to figure this stuff out, The main tools are Jesse Rudderman's javascript shell bookmarklet and Joe Hewitt's Firebug extension. I also use the Web Developer extension on occasion and a a whole bunch of Jesse's bookmarklets, but those don't really affect this. I find firebug to be a lot more convenient to work with than the DOM Inspector.

I set a keyboard shortcut for all the bookmarklets (e.g. the js shell is 'shell') and the address bar then acts more or less like a command line. It's very convenient.

Donald:

You were using my version of the script and currently have mihai's installed. Install my version and you'll get the behavior you expect.
Karl, thanks for giving the heads up on tools that you use. I am finding this work to be quite manageable and a great way to become familiar with DHTML and javascript techniques. As you noted, your laziness just had you patch mihai's script, but your update did not fix the problem. I updated your script to properly reflect the changes in mihai's original. I look forward to figuring out more things and extending this great tool.

http://abcsnaturally.com/gmailmacros.user.js
Argh, it is seemingly broken again. Why won't Google leave the entity names alone?
Karl, u r GREAT !

All macro keys are working beautifully. Mark 'All/None' etc. have made me forget about my mouse.

I made few changes to have the '?' help box show properly in middle of page. Also changed 'V' to 'B' for mark unread, as 'V' is taken by 'View Conversation' script. Also changed '9000' to 'Karl_G' in honour.

Now, can u add a macro key for 'Remove Label' ?
I do it now via (from inbox) : x g [label] y g i
But it will be better if (say) : h [label]
Anand K Gupta
please post your version, i would like to try. it sounds nice

thanks
Anand K Gupta, you also need to change the help box text for mark unread from 'V' to 'B'.
Looks like it is broken again? Anybody have a new version?
ben, it seems to be working ok for me. perhaps the cl2 update has rolled out to your account and they messed up the all the node IDs again. do you have the cl2 features?
Hi Sam,
Thanks, I have changed the help box text for mark unread from 'V' to 'B' and have uploaded it, to same link. It is working great.

Hey Karl, when are you going to give the remove_label shortcut key ?
how would I know if I am seeing the cl2 features?
ok so I guess since cl2 came out, it is fair to say that is what is causing the problem. Is anybody else having this issue. Would love to get it fixed or does anybody know another by which I can do labelling as quickly as with the macro script?
Thanks Karl for the cool extensions to the macros. One thing I noticed is that after you use some of the macros, other normal keys become disabled. For example, if I use M U R (mark all unread, then mark them as read), the spacebar (page down) and the page up/down keys no longer function. I generally have to use a G+label shortcut to get them reset. I haven't noticed this behavior with the base gmail macros.
mkizer: i am working on fixing this among other feature enhancements to the script. I will post when finished and debugged.
Man, I am really frustrated. I still cannot get this to work. When I do G+ [tag name] or L+ [tag name] only Inbox, Starred, and Trash work. All of my other labels are not recognized. I have tried all of the above versions of the script with the same results. Anyone have any advice?? I am desperate.
answered my own question and figured I'd post in case anybody runs into this. Turns out I had to have the labels box in the left column open to make it work.
Thanks ben, we may have fallen into it.
I love this macro, but i'm having a bit of trouble with the onscreen shortcut menu. I am told that entering "?" will bring this up, but I can't seem to get it to work. How does one bring this help menu up for a shortcut refresher?
Hi Alex,

Try pressing ? two/three times. It sometime happens to me, but pressing ? repeatedly pops the help.
Alex, are you having issues with other functions of the script?
It looks like Google changed something and this is broken again. Is anyone else having issues?
Thanks everyone for the great script. It makes applying labels so much more manageable and much faster to do the other actions also. The one thing I have been thinking about a long time but don't have the programming experience to implement is another labelling technique. would it be possible to add a +/- sign next to each label on the left hand column. these would only be usable when a message is selected and the - sign only visible if the currently selected message contains that label. basically makes the dropdown labels selecter moot. hate having to use the dropdown to remove wrongly applied labels. thanks
Jim, I had some problems briefly when Firefox was updated to v1.5.0.3 and I just figured that Greasemonkey needed to be updated. But, after shutting down Firefox and restarting it the next day, all was well.
One suggestion. i have been making this mistake often but not sure if it bugs others also. When I am going through my email and labelling items I often forget i have to check an item before i can perform an action on it ie labelling it. how about preventing that little label grey box from popping up unless an item is already checked. I guess i mean only activate those key commands if at least one item is checked.
I was having the same label "problems" as ben so I hacked the script to open the labels when you press l or g, and then close it when the label action is escaped or completed. It's not terribly elegant, but it works.


// Added this to globals
var closeLabels = false;

// Added this to beginLabelAction ( after line 2 )
if (divs.length == 3){
fireMouseEvent(getNode("nt_0"));
divs = getNode("nb_0").getElementsByTagName("div");
closeLabels=true;
}

// Added this to the end of endLabelAction
if ( closeLabels )
fireMouseEvent(getNode("nt_0"));
I'm having trouble getting Gmail macros to work. 'g' does work, pops up a box for me to type a label, but 'm' and '?' does nothing. I've tried reinstalling the script, and even reinstalling Greasemonkey, but it doesn't help. However, on my work computer, with pretty much the same extensions, everything works perfectly. Anyone have ideas?

thanks for your help
I am using the standard version from here (not Karl's modded) and can't get a list of commands to pop up. I would really like to use this script, but I don't want to look at its source every time I can't recall what the scripts were.
So, what and where is the latest version of the gmail macros script? I too have a few problems, like the '?' not bringing up the help.
Hi Phong, Andrew and chb,

You can try the script from my site as below,
http://coral.anand.googlepages.com/gmail-macros.user.js

It has all enhancements of Karl on mihai's script.

For '?' popup, you may need to press ? repeatedly sometimes.
Anand,
I tried the updated script as you suggested, and everything seems fine now. Thanks!
Anand,

I'm running your script and using Firefox 1.5.0.4. 'D' never gets beyond 'marked as read'; I have to then run an additional 'Y' command to have the email archived. Is there any obvious reason why this might be so?
HI David
Yes, 'D' does not seem to work for mark-read-and-archive. I tried but could not fix it. It was originaly done by Mihai, may be Karl can help.
#quote by=sewpafly
I was having the same label "problems" as ben so I hacked the script to open the labels when you press l or g, and then close it when the label action is escaped or completed. It's not terribly elegant, but it works.
#code
#/quote

Thanks man... it works like a charm. And, No, I dont mind if it opens the labels box for a moment.

I think it should be included in the base script and made available fr people to download directly...

BTW... this is my first JS hack, although a copy-paste... ;) but still... :)

Thanks again..
The 'D' command doesn't actually use a direct api call, it instead sends a 'mark as read' waits and then 'archive'. I find that having too many messages selected causes the timeout not to be long enough. It'd be nice if this was an atomic operation.
Is anyone else getting a problem with this script working as of recently?
Hi Everyone,

Good news. Now gmail-macro supports "Remove Label" short-cut.

"B" = Remove Label
"V" = Mark UnRead (as was done my Karl)

The latest script available at:
http://coral.anand.googlepages.com/gmail-macros.user.js

Hope all macro lovers find it more useful now.

Anand
Hi Everyone,

Mihai had done the job of marking the "Remove label" id but somehow he did not put the codes around. Karl also missed it. It took me some time to figure out how to use the "Label" codes to "UnLabel" logic. The beauty of the script is that it works on color coded labels, even when colors are visible (a feature most of us were requesting for long).

Anand
I use the excellent Firefox extension GTDGmail (www.gtdgmail.com) which uses label prefixes e.g. "S:Action", "S:Next Action", "C:Home" etc)

G+label does not seem to work with these labels.

Any pointers for tweaking?

Thanks for an excellent script!

Pete
It seems to have broken again. Gmail went down for a little bit today and after it came back up, this extension stopped working for me.
Hmm... it appears that the macros (among other GMail Greasemonkey scripts) stopped working for me today (I tried it on two different machines). Perhaps Google changed some things...
It appears that the mouseevent code no longer works. I figured that out, but I don't seem to be smart enough to figure out how to fix it. There is a comment by Mihai in the code that says "event.target gets set to the document (and is read-only, so we can't set it by hand). Unfortunately, labelDiv.createEvent doesn't work either. However, Gmail checks for both srcElement and target, so we can fake it this way." I'm wondering if Google stopped checking the srcElement field.
Macros all stopped working today. I've tried it on 5 different machines. Did Google do something? I can't live without these great scripts!!!!
I ran into the mouse code not working this morning and I've updated my script. The updated script should work in either case, as it removes a workaround mihai put in. Details follow.

event.target gets set to the element you dispatchEvent on. This means that you need to change all document.dispatchEvent to .dispatchEvent. In mihai's version, there's only one document.dispatchEvent and that should be changed to labelDiv.dispatchEvent. The srcElement added in the line above that change isn't needed, so it (and the comment above it) should be removed.
Thanks Karl for the info. I was using Anand's version (of your version ;-) and found two instances of the document.dispatchEvent work around. I changed them both and the G shortcut now works. However, M still does not function.
Ah, nevermind... Karl's version does indeed allow the M shortcut to work. Maybe I'll just try adding the B (remove label) functionality to Karl's script...unless he beats me to it. ;-)
K, it was fairly easy to add the B (remove label) code into Karl's script. I also tweaked the position of the help box so it would appear correctly on my display (changed bottom from 60% to 20%)...not sure if others have that issue or not. You can grab the script here: http://michael.kizer.ws/blog_upload/2006/10/gmail-macros-user.js
Ack! I didn't notice that my blog upload b0rked the filename... anyway here is the link to the blog article and the macros directly:
http://michael.kizer.ws/2006/04/18/supercharging-gmail/
http://michael.kizer.ws/blog_upload/2006/10/gmail-macros.user.js
mkizer, you probably made the same changes in both places when you edited my script. I actually use a different variable name than mihai does, so for each you have to match the variable name that's in context. Anyway, I've done a quick add of a B key to my version. I'm thinking about shuffling around the keyboard shortcuts to have shift+key reverse key, so that shift+L would be remove label, shift+R is unread, etc. I think it'd create a more reasonable set of shortcuts. Thoughts?
KarlG, I think using the shift+L and shift+R is a great idea. Much better sense than Z and B. And thanks for the fix on the mouse event code. Works like a charm.
shift L and shift R is a great idea.
Guys listen. These "quicksilver" shortcut are --- FANTASTIC!. I cannot live without them, so please continue to update the scripts as Google and Firefox evolve. For what it's worth, I'ld like to leave the shortcut keys alone as I can really move around quickly. Thanks for all the work on these program. You're the best!!!
Seems like some changes today on Gmail have broken again this very useful script. The combination of g+label no longer works (for example), but the labelling, etc. does
Thanks for the update Karl. One otehr thing that Anand had in his code was an addition that allowed the G shortcut to function from the Contacts section, here is his modified piece:
// Action or contacts menus is present
return (getActionMenu() != null) || (getNode("co") != null);

In other news... I think the shift modifiers might be a good idea to kind of keep the keyboard shortcuts consistant.

Karl (and others), I just started a Google Group for GMail power Users (Greasemonkey scripts, add ons, etc.) so people can chat about their latest scripts for enhancing GMail, plus it'll give people a place to upload their scripts for others to share. It will be much easier than continually replying to the comment threads in Mihai's blog. ;-)
The address is: http://groups-beta.google.com/group/gmail-power-users
it is totally bare right now, but I'll be adding some content shortly...for now fee free to sign up and chat away...
Seconding the report from jmcastagnetto... the script is semi-broken as of 10/25. Labeling still works, but navigating (g+ labelname) does NOT work.

Mihai: this script is ESSENTIAL. My life creaks to a halt without it. Okay, that's exaggerating... but please give us a fix!
This same conversation is going on in two different posts on this blog with two different alternate version of the gmail macros script.



http://persistent.info/archives/2005/12/23/greasemonkey

http://persistent.info/archives/2006/03/21/gmail-macros



Has anybody tried both? Are Boris, mkizer, Karl (and Mihai?) collaborating at all on this?
Anand/Karl/Brent have done some nice work in hacking this thing back to working order. I know it's already been mentioned, but if you're new to this script, be sure to check out the new GMail Power Users group:
http://groups-beta.google.com/group/gmail-power-users

We're posting various versions of the script on the group, as well as having a lively discussion.
It seems that no matter which version of gmailmacros, greasemonkey, Firefox, or even hardware that I use, I cannot get the help screen to show by pressing "?"
Hi Seth,

Below is the extract from the script help file,

"?" : "Displays this help message"
"T" : "Trash a message or conversation"
"E" : "Archive always/remove from inbox"
"R" : "Mark as Read a message or conversation"
"V" : "Mark as Unread a message or conversation"
"D" : "Discards (Read&Archive) a message or conversation"
"G+label" : "Go to a label (including inbox/star/trash/etc)."
"L+label" : "Applies label to conversation(s)"
"B+label" : "Removes label from conversation(s)"
"M+key" : "Mark (Select) A: all, N: none, R: read, U: Unread, S: starred, T: Unstarred"
"O" : "Expands/Collapses all messages in conversation"

These are above and all of the normal key shortcuts of GMAIL, like "U", "X" etc.

Try disabling any other script and enabling only macro script, and then see if it works ok or not. May be the other scripts are clashing with this script. Also try pressing '?' key repeatedly, sometime pressing it once do not work, even in my machine.

HTH

Anand
The 'm' key some versions of the scripts use for marking messages has been taken by the Gmail team. 'm' now stands for 'mute'.

http://mail.google.com/support/bin/answer.py?answer=47787
Great resource. For some reason, I can't seem to get the "Label" funtion to work. I hit the "L" key and gray box appears saying:
"GMailMacros: sewpafly flavor"
I can't seem to access the my Labels.

FWIW- I am running GTD extensions.

Any advice/suggestions?

Thanks,
Sasha
I'm having trouble using this script with Gmail in Firefox 2.0.0.1. When I select a message (or open it) and click Y for example to archive it (that's what it says in the instructions), Firefox starts doing a quick find. Strange because H (for help) works but the other commands don't.

And also, for the first command in help it says "C* Compose" with the C in compose in yellow. So do I need to type C* or C to compose a new message?
Why run a blog if you don't reply to any of the comments?
Thanks for the updates guys.

PS. Max--Try http://groups.google.com/group/gmail-power-users instead. I'm sure he's quite busy...
I would like to find a script that would put a little check box next to all e-mails that would allow me to click on it and make a rule for this sender called "always archive" that way I could clean up my inbox from stuff i don't want to see but still have it in case I do. I have tried making a rule for each one but it takes too long. Could anyone make a script like that? Timjordan AT cheerful.com
The Help Window does NOT come up on pressing the "?" key...


Selecting a message and then pressing l for label does bring up the labeling dialog.

Disbaled all other extensions and Greasemonkey scripts... still not working.

The "Gmail color labels" greasemonkey script works fine...

Also tried the Gmail Macros - BN version from the google group... even that does not bring up the help screen on pressing "?"
Hello Anonymous,

The help popup key is changed to "h" from "?", in the latest script.

Try pressing "h" key.

HTH

Regards,

Anand
Thanks Anand,

that was it!

I am a happy camper now!!
Well well, Gmail 2 now have inbuilt label colors ! and they remain persistent (obviously, from Gmail Team now). Help on keyboard shortcut is also displayed via '?' key, in similar format of Mihai's original macro script.

Hey Mihai, did they contacted you for taking the leaf out of your book ?

Post a Comment