When a person is unable to perform the mitzvah of nichum aveilim in person, he may call and comfort the mourners by phone. This is not the preferred method because doing so only fulfills part of the mitzvah – it serves as a comfort for the mourner but not for the deceased. Nevertheless, if one is truly unable to appear in person, a phone call is preferable to not performing nichum aveilim at all (Iggros Moshe, OC IV, 40:11).
The rules about waiting for the mourner to initiate the conversation are different when making a shiva call by phone. For example, the caller is permitted to identify himself before the mourner addresses him. Some permit the caller to begin speaking right away, considering the mourner having taken the phone as tantamount to starting the conversation.
While technically permitted, the practice is not to perform nichum aveilim on Shabbos (Orach Chaim 287:1, Mishnah Brurah). If one sees a mourner on Shabbos, he should wish him “Shabbos hi milnacheim unechama krova lavo,” “Shabbos is not a time for consolations but comfort will come soon,” though some permit the standard text of HaMakom to be used (Mishnah Brurah 287:3).
If one does not see a mourner until after shiva has ended, he may still bless him with the text of “HaMakom…” for the full 12 months (in the case of one mourning for a parent) or 30 days (for other relatives). After 12 months or 30 days (respectively), one simply wishes the mourner “tisnacheim,” “may you be comforted” (Yoreh Deah 385:2).