Keyconfig extension: Thunderbird

From MozillaZine Knowledge Base
Jump to navigationJump to search
This article was written for Thunderbird but also applies to Mozilla Suite / SeaMonkey (though some menu sequences may differ).

This article lists code samples that you can use for shortcut keys and buttons in Thunderbird. The samples are categorized by the type of code, and by the Thunderbird window that the code works in. If you are looking for code for a particular purpose, use your browser's Find feature to search this page.

The code samples here are mostly case-sensitive. To avoid typing errors, copy code samples from this page and paste them.

You can use the code here in any extensions that provide shortcut keys, menu items or buttons. For example, see: Keyconfig extension and MenuManipulator

Simple built-in commands

Thunderbird has many built-in commands that you can use by name. If a built-in command exists for what you want to do, then it is usually the best way to set up a shortcut key.

If you press your shortcut key when the command is not enabled, nothing happens. This protects Thunderbird from error conditions. To override it, you can sometimes use functions instead of commands. For example, the applyFilters command is disabled in the message window, but the MsgApplyFilters function works there. Functions are described in the sections below.

To call a built-in command, use code like this, replacing command with the actual name of the command:

goDoCommand("cmd_command")

For example, to run the current folder's filters use this code:

goDoCommand("cmd_applyFilters")

Main window and message window

The main window and the message window share commands, but some of them are disabled in one window or the other.

applyFilters
close
collapseAllThreads
compactFolder
createFilterFromMenu
delete
deleteJunk
downloadFlagged
downloadSelected
editAsNew
emptyTrash
expandAllThreads
find
findAgain
findPrevious
forward
forwardAttachment
forwardInline
getMsgsForAuthAccounts
getNewMessages
getNextNMessages
goBack
goForward
goStartPage
killThread
markAllRead
markAsFlagged
markAsJunk
markAsNotJunk
markAsRead
markReadByDate
markThreadAsRead
moveToFolderAgain
nextFlaggedMsg
nextMsg
nextUnreadMsg
nextUnreadThread
openMessage
previousFlaggedMsg
previousMsg
previousUnreadMsg
print
printpreview
printSetup
properties
recalculateJunkScore
redo
reload
renameFolder
reply
replyall
replyGroup
replySender
runJunkControls
saveAsFile
saveAsTemplate
search
selectAll
selectThread
sendUnsentMsgs
SetFocusFolderPane
SetFocusMessagePane
SetFocusThreadPane
setFolderCharset
settingsOffline
shiftDelete
stop
synchronizeOffline
undo
viewAllMsgs
viewIgnoredThreads
viewPageSource
viewThreadsWithUnread
viewUnreadMsgs
viewWatchedThreadsWithUnread
watchThread

Compose window

HTML:

abbr
acronym
bold
cite
code
em
form
hline
image
italic
nobreak
ol
samp
strikethrough
strong
subscript
superscript
tt
ul
underline
var

Miscellaneous:

account
attachFile
attachPage
attachVCard
close
copy
cut
decreaseFont
delete
increaseFont
indent
insert
openAttachment
outdent
paste
pasteNoFormatting
pasteQuote
print
printSetup
quoteMessage
redo
rewrap
saveAsDraft
saveAsFile
saveAsTemplate
saveDefault
selectAll
sendButton
sendLater
sendNow
sendWithCheck
showComposeToolbar
showFormatToolbar
spelling
undo

Address book

copy
cut
delete
paste
printcard
printcardpreview
properties
redo
selectAll
undo

Built-in commands with parameters

In a few cases, a built-in command requires a parameter to specify exactly what the command does. To call one of these commands, use code like this, replacing command with the actual name of the command, and replacing parameter with the actual parameter value:

doStatefulCommand("cmd_command", parameter)

For example, to center text in the Compose window use this code:

doStatefulCommand("cmd_align", "center")

For the default value, omit the parameter. For example, to remove any alignment use this code:

doStatefulCommand("cmd_align")

Compose window

Command Parameter
align text alignment: "left", "right", "center", "justify"
backgroundColor color—for example: "yellow"
fontColor color—for example: "red"
fontFace font face—for example: "Verdana"
fontSize font size (1 – 7)—for example: 5
paragraphState paragraph format tag—for example: "h3"
smiley smiley (for a list, see: here)—for example: ":)"

Simple built-in functions

Thunderbird also has many built-in functions, and some of them can be called by shortcut keys.

When your shortcut key calls a simple built-in function, there might be no check that the function is enabled. If you call a function that is not enabled, then it might have unexpected side-effects, and in some cases you might lose data or even crash Thunderbird. For example, if you run the MsgApplyFilters function when no folder is selected, it causes an error (but does no actual harm).

To call a built-in function, add empty parentheses after the function name. For example, to add a new tag use this code:

AddTag()

Main window and message window

AddTag
checkForUpdates
CopyFolderUrl
CopyMessageUrl
deleteJunkInFolder
LoadMsgWithRemoteContent
MsgAccountManager
MsgApplyFilters
MsgAccountWizard
MsgBodyAllowHTML
MsgBodyAsPlaintext
MsgBodySanitized
MsgCompactFolder
MsgDeleteFolder
MsgEditMessageAsNew
MsgEmptyTrash
MsgFilters
MsgFolderProperties
MsgGroupBySort
MsgIsNotAScam
MsgMarkAllRead
MsgNewFolder
MsgNewMessage
MsgOpenFromFile
MsgOpenNewWindowForMessage
MsgRenameFolder
MsgSaveAsFile
MsgSearchAddresses
MsgSortAscending
MsgSortByAttachments
MsgSortByDate
MsgSortByFlagged
MsgSortByJunkStatus
MsgSortByOrderReceived
MsgSortByPriority
MsgSortByRecipient
MsgSortBySender
MsgSortBySize
MsgSortByStatus
MsgSortBySubject
MsgSortByTags
MsgSortByUnread
MsgSortDescending
MsgSortThreaded
MsgSortUnthreaded
MsgStop
MsgSubscribe
MsgToggleMessagePane
MsgUnsubscribe
MsgViewAllHeaders
MsgViewNormalHeaders
openAboutDialog
openNewCardDialog
openOptionsDialog
PrintEnginePrint
PrintEnginePrintPreview
QuickSearchFocus
RemoveAllMessageTags
saveViewAsVirtualFolder
toAddressBook
ToggleFavoriteFolderFlag
toImport
toJavaScriptConsole
toMessengerWindow

Compose window

goOpenNewMessage
openAboutDialog
toAddressBook
toggleAddressPicker
toMessengerWindow

Address book

AbClose
AbExport
AbIMSelected
AbNewAddressBook
AbNewLDAPDirectory
AbNewMessage
AbPrintAddressBook
AbPrintPreviewAddressBook
AbSortAscending
AbSortDescending
AbSwapFirstNameLastName
goQuitApplication
NSPrintSetup
onAdvancedAbSearch
openAboutDialog
openOptionsDialog
QuickSearchFocus
toImport
toMessengerWindow

Built-in functions with parameters

In some cases, a built-in function requires a parameter to specify the result. To call a built-in function that requires a parameter, use code like this, replacing function with the name of the function, and replacing parameter with the parameter value:

function(parameter)

For example, to view folders with unread messages:

loadFolderView(1)

Main window

Function Parameter
ChangeMailLayout 0 Classic, 1 Wide, 2 Vertical
CustomizeMailToolbar "mail-toolbox"
loadFolderView 0 All, 1 Unread, 2 Favorite, 3 Recent
ViewChangeByValue 9 for the first custom view, 10 for the next, and so on
MsgFolderProperties "QuotaTab" (optional)
MsgMoveMessage Folder URI in quotes—for example: "mailbox://someone@pop.example.com/Inbox"
MsgCopyMessage Folder URI in quotes
toOpenWindowByType Dialog type and URL (see below)
messenger.launchExternalURL URL in quotes—for example: "http://www.mozilla.com/"

Dialog type and URL
A few dialog windows can be opened directly by the toOpenWindowByType function. For example, to open the config editor:

toOpenWindowByType("Preferences:ConfigManager", "chrome://global/content/config.xul")

The dialogs that can be opened like this are:

"mailnews:junklog","chrome://messenger/content/preferences/junkLog.xul"
"Toolkit:PasswordManager", "chrome://messenger/content/preferences/viewpasswords.xul"
"Preferences:DownloadActions", "chrome://messenger/content/preferences/downloadactions.xul"
"Preferences:ConfigManager", "chrome://global/content/config.xul"
"Update:History", "chrome://mozapps/content/update/history.xul"
"mozilla:certmanager", "chrome://pippki/content/certManager.xul"
"mozilla:devicemanager", "chrome://pippki/content/device_manager.xul"
"Download:Manager", "chrome://mozapps/content/downloads/downloads.xul"

Compose window

Function Parameter
CustomizeMailToolbar "compose-toolbox"
openOptionsDialog "paneCompose" (optional)

Address book

Function Parameter
AbNewCard "dirTree"
AbNewList "dirTree"
CustomizeMailToolbar "ab-toolbox"
MapIt "cvHomeMapIt" or "cvWorkMapIt"
openLink "cvWorkWebPage"
SetNameColumn "firstLastCmd", "lastFirstCmd" or "displayNameCmd"
SortResultPane "GeneratedName", "PrimaryEmail", "_AimScreenName", "Company", "_PhoneticName", "NickName", "SecondEmail", "Department", "JobTitle", "CellularNumber", "PagerNumber", "FaxNumber", "HomePhone" or "WorkPhone"

Built-in functions with Shift-key parameters

In some cases, a built-in function is designed to detect whether the Shift key is pressed. To allow it to do this, include the parameter: event   To prevent it, making the function think the Shift key is pressed, include the parameter: {shiftKey: true}   To prevent it, making the function think the Shift key is not pressed, include the parameter: {shiftKey: false}

For example, to write a new message and switch the editor type (HTML or plain text) to the opposite of the default, regardless of whether your shortcut uses the Shift key:

MsgNewMessage({shiftKey: true})

Main window

MsgForwardAsAttachment
MsgForwardMessage
MsgNewMessage
MsgReplyGroup
MsgReplySender
MsgReplyToAllMessage

Custom code

Shortcut keys can run custom code to perform actions that are not supported by any of the methods above.

Main window and message window

Display file path of current profile:

with (Components.classes["@mozilla.org/file/directory_service;1"]
  .getService(Components.interfaces.nsIProperties)
  .get("ProfD", Components.interfaces.nsIFile))
  prompt("Profile: " + path, path)

Display build identification string:

with (navigator) prompt("Build: " + userAgent, userAgent)

Display additional build information:

GetMessagePaneFrame().location.href = "about:buildconfig"
if (IsMessagePaneCollapsed()) MsgToggleMessagePane()
HideMessageHeaderPane()

Display current folder URI:

with (GetSelectedFolderResource()) prompt("URI: " + URI, URI)

Toggle inline display of attachments:

ToggleInlineAttachment(
 document.getElementById("viewAttachmentsInlineMenuitem"))

Toggle message body between plain text and HTML:

pref.getBoolPref("mailnews.display.prefer_plaintext")?
 MsgBodyAllowHTML():MsgBodyAsPlaintext()

Toggle plain text messages between fixed width and proportional font:

pref.setBoolPref("mail.fixed_width_messages",
 !pref.getBoolPref("mail.fixed_width_messages")),
MsgReload()

Toggle selected messages replied-to:

for each (var uri in GetSelectedMessages()) {
  var hdr = messenger.msgHdrFromURI(uri)
  GetDBView().db.MarkReplied(hdr.messageKey,
   (hdr.flags & 2) == 0, null)}

Toggle selected messages forwarded:

for each (var uri in GetSelectedMessages()) {
  var hdr = messenger.msgHdrFromURI(uri)
  GetDBView().db.MarkForwarded(hdr.messageKey,
   (hdr.flags & 0x1000) == 0, null)}

Go to a specific folder. Customize the first line to specify the folder URI.

const uri = "mailbox://someone@pop.example.com/Inbox"
with (document.getElementById("folderTree").view)
  for (var i = 0; i < rowCount; ++i) with (getResourceAtIndex(i))
    uri == Value? selection.select(i) :
    uri.indexOf(Value) == 0 && !isContainerOpen(i)? toggleOpenState(i) : null

Toggle the folder pane between All Folders and Favorite Folders:

loadFolderView(gCurrentFolderView == 0? 2:0)

Get messages for the currently-selected account:

GetMessagesForInboxOnServer(gMsgFolderSelected.server)

Get messages for a specific account (specifying the user name, server host name, and server type):

GetMessagesForInboxOnServer(accountManager.FindServer("someone", "pop.example.com", "pop3"))

Toggle between online and offline:

MailOfflineMgr.toggleOfflineStatus()

Compose window

Each of these samples is just one line:

InlineSpellCheckerUI.addToDictionary()
InlineSpellCheckerUI.mInlineSpellChecker.ignoreWord(InlineSpellCheckerUI.mMisspelling)
enableInlineSpellCheck(!InlineSpellCheckerUI.enabled)
GetCurrentEditor().insertText("Hello")
GetCurrentEditor().insertHTML("<b>Hello</b>")

MoreButtonsPlus extension

Each of these samples is just one line:

ToggleHeadersButton()

Mnenhy extension

Each of these samples is just one line:

goMnenhy.headers.ToggleHeaderViewBrief()
goMnenhy.headers.SetView(goMnenhy.headers.gkiViewNoHeaders)
goMnenhy.headers.SetView(goMnenhy.headers.gkiViewNormalHeaders)
goMnenhy.headers.SetView(goMnenhy.headers.gkiViewAllHeaders)
goMnenhy.headers.SetView(goMnenhy.headers.gkiViewCustomBase)

External links