To answer the original question, on my Ranger I have a hotbutton set up to forage, just like many Rangers do. It's in slot #3 on my hotbutton list, and in addition in the Options screen I set my "turn left" key (which is A, I use WASD to move most of the time) to also activate hotbutton #3.
Okay, the easiest thing to do is to just put the Forage skill into hotbutton slot #3 and that's it. But you can make it better. You do this by using the "/autoinventory" command. You would make a macro that looked like this:
/autoinventory
/doability #
/pause 5
/autoinventory
The explanation: /autoinventory puts whatever is on your cursor into your inventory. I think you should be able to have multiple items on your cursor (like when you Summon Food multiple times in a row), but this is just being safe. /doability # activates Forage. However, this time Forage has to be over in the Actions menu, which in the default UI is over at the bottom right of the screen. It's the one which has 4 tabs to it, with Action, Social, etc. You just click on one of the Skill buttons to set it to Forage and note which number it is, and use that one. The /pause 5 gives a short delay before the final /autoinventory puts the newly foraged item into your inventory.
There are a few disadvantages to the second method. Using the first method, the Forage button darkens until it can be used again, because it is only the skill. With the second method you don't know when you can use it again, but since you use it automatically every time you turn left it doesn't really matter too much. The second problem only really happens in LDoNs...since several items that can be foraged also drop from mobs, and they can be worth 30-70 pp or more in the Bazaar, if you are ML and honest it can be hard to remember which ones belong to the group and which ones belong to you. Not too hard to work around if you care enough, just something to remember.
Of course you could always make a hotbutton that Forages, waits 5 minutes, Forages again, etc., but that can interfere with your other hotbuttons so it's not adviseable unless you're just sitting around Foraging.
Hopefully I didn't ***** that up, it's mostly from memory but doing a Google search on /autoinventory also brought up some other Foraging advice.
Game on,