Create and manipulate toolbars which can be attached to the Hammerspoon console or hs.webview objects.
Toolbars are attached to titled windows and provide buttons which can be used to perform various actions within the application. Hammerspoon can use this module to add toolbars to the console or hs.webview
objects which have a title bar (see hs.webview.windowMasks
and hs.webview:windowStyle
). Toolbars are identified by a unique identifier which is used by OS X to identify information which can be auto saved in the application's user defaults to reflect changes the user has made to the toolbar button order or active button list (this requires setting hs.webview.toolbar:autosaves and hs.webview.toolbar:canCustomize both to true).
Multiple copies of the same toolbar can be made with the hs.webview.toolbar:copy method so that multiple webview windows use the same toolbar, for example. If the user customizes a copied toolbar, changes to the active buttons or their order will be reflected in all copies of the toolbar.
Example:
t = require("hs.webview.toolbar")
a = t.new("myConsole", {
{ id = "select1", selectable = true, image = hs.image.imageFromName("NSStatusAvailable") },
{ id = "NSToolbarSpaceItem" },
{ id = "select2", selectable = true, image = hs.image.imageFromName("NSStatusUnavailable") },
{ id = "notShown", default = false, image = hs.image.imageFromName("NSBonjour") },
{ id = "NSToolbarFlexibleSpaceItem" },
{ id = "navGroup", label = "Navigation", groupMembers = { "navLeft", "navRight" }},
{ id = "navLeft", image = hs.image.imageFromName("NSGoLeftTemplate"), allowedAlone = false },
{ id = "navRight", image = hs.image.imageFromName("NSGoRightTemplate"), allowedAlone = false },
{ id = "NSToolbarFlexibleSpaceItem" },
{ id = "cust", label = "customize", fn = function(t, w, i) t:customizePanel() end, image = hs.image.imageFromName("NSAdvanced") }
}):canCustomize(true)
:autosaves(true)
:selectedItem("select2")
:setCallback(function(...)
print("a", inspect(table.pack(...)))
end)
t.attachToolbar(a)
Notes:
hs.webview
is not. To load this module directly, use require("hs.webview.toolbar")
instead of relying on module auto-loading.Signature | hs.webview.toolbar.itemPriorities |
---|---|
Type | Constant |
Description |
A table containing some pre-defined toolbar item priority values for use when determining item order in the toolbar. |
Source | extensions/webview/libwebview_toolbar.m line 1938 |
Signature | hs.webview.toolbar.systemToolbarItems |
---|---|
Type | Constant |
Description |
An array containing string identifiers for supported system defined toolbar items. |
Source | extensions/webview/libwebview_toolbar.m line 1926 |
Signature | hs.webview.toolbar.attachToolbar([obj1], [obj2]) -> obj1 |
---|---|
Type | Function |
Description |
Get or attach/detach a toolbar to the webview, chooser, or console. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 863 |
Signature | hs.webview.toolbar:inTitleBar([state]) -> toolbarObject | boolean |
---|---|
Type | Function |
Description |
Get or set whether or not the toolbar appears in the containing window's titlebar, similar to Safari. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 986 |
Signature | hs.webview.toolbar.uniqueName(toolbarName) -> boolean |
---|---|
Type | Function |
Description |
Checks to see is a toolbar name is already in use |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 846 |
Signature | hs.webview.toolbar.new(toolbarName, [toolbarTable]) -> toolbarObject |
---|---|
Type | Constructor |
Description |
Creates a new toolbar for a webview, chooser, or the console. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 809 |
Signature | hs.webview.toolbar:addItems(toolbarTable) -> toolbarObject |
---|---|
Type | Method |
Description |
Add one or more toolbar items to the toolbar |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview_toolbar.lua line 53 |
Signature | hs.webview.toolbar:allowedItems() -> array |
---|---|
Type | Method |
Description |
Returns an array of all toolbar item identifiers defined for this toolbar. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1657 |
Signature | hs.webview.toolbar:autosaves([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description |
Get or set whether or not the toolbar autosaves changes made to the toolbar. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1853 |
Signature | hs.webview.toolbar:canCustomize([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description |
Get or set whether or not the user is allowed to customize the toolbar with the Customization Panel. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1827 |
Signature | hs.webview.toolbar:copy() -> toolbarObject |
---|---|
Type | Method |
Description |
Returns a copy of the toolbar object. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1040 |
Signature | hs.webview.toolbar:customizePanel() -> toolbarObject |
---|---|
Type | Method |
Description |
Opens the toolbar customization panel. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1792 |
Signature | hs.webview.toolbar:delete() -> none |
---|---|
Type | Method |
Description |
Deletes the toolbar, removing it from its window if it is currently attached. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 2066 |
Signature | hs.webview.toolbar:deleteItem(identifier) -> toolbarObject |
---|---|
Type | Method |
Description |
Deletes the toolbar item specified completely from the toolbar, removing it first, if the toolbar item is currently active. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1557 |
Signature | hs.webview.toolbar:displayMode([mode]) -> toolbarObject |
---|---|
Type | Method |
Description |
Get or set the toolbar's display mode. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1281 |
Signature | hs.webview.toolbar:identifier() -> identifier |
---|---|
Type | Method |
Description |
The identifier for this toolbar. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1775 |
Signature | hs.webview.toolbar:insertItem(id, index) -> toolbarObject |
---|---|
Type | Method |
Description |
Insert or move the toolbar item to the index position specified |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1177 |
Signature | hs.webview.toolbar:isAttached() -> boolean |
---|---|
Type | Method |
Description |
Returns a boolean indicating whether or not the toolbar is currently attached to a window. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1023 |
Signature | hs.webview.toolbar:isCustomizing() -> bool |
---|---|
Type | Method |
Description |
Indicates whether or not the customization panel is currently open for the toolbar. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1810 |
Signature | hs.webview.toolbar:itemDetails(id) -> table |
---|---|
Type | Method |
Description |
Returns a table containing details about the specified toolbar item |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1593 |
Signature | hs.webview.toolbar:items() -> array |
---|---|
Type | Method |
Description |
Returns an array of the toolbar item identifiers currently assigned to the toolbar. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1674 |
Signature | hs.webview.toolbar:modifyItem(table) -> toolbarObject |
---|---|
Type | Method |
Description |
Modify the toolbar item specified by the "id" key in the table argument. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1414 |
Signature | hs.webview.toolbar:notifyOnChange([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description |
Get or set whether or not the global callback function is invoked when a toolbar item is added or removed from the toolbar. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1155 |
Signature | hs.webview.toolbar:removeItem(index | identifier) -> toolbarObject |
---|---|
Type | Method |
Description |
Remove the toolbar item at the index position specified, or with the specified identifier, if currently present in the toolbar. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview_toolbar.lua line 97 |
Signature | hs.webview.toolbar:savedSettings() -> table |
---|---|
Type | Method |
Description |
Returns a table containing the settings which will be saved for the toolbar if hs.webview.toolbar:autosaves is true. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1090 |
Signature | hs.webview.toolbar:selectedItem([item]) -> toolbarObject | item |
---|---|
Type | Method |
Description |
Get or set the selected toolbar item |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1708 |
Signature | hs.webview.toolbar:selectSearchField([identifier]) -> toolbarObject | false |
---|---|
Type | Method |
Description |
Programmatically focus the search field for keyboard input. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1741 |
Signature | hs.webview.toolbar:separator([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description |
Get or set whether or not the toolbar shows a separator between the toolbar and the main window contents. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1111 |
Signature | hs.webview.toolbar:setCallback(fn) -> toolbarObject |
---|---|
Type | Method |
Description |
Sets or removes the global callback function for the toolbar. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1062 |
Signature | hs.webview.toolbar:sizeMode([size]) -> toolbarObject |
---|---|
Type | Method |
Description |
Get or set the toolbar's size. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1234 |
Signature | hs.webview.toolbar:toolbarStyle([style]) -> toolbarObject |
---|---|
Type | Method |
Description |
Get or set the toolbar's style. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview_toolbar.m line 1333 |
Signature | hs.webview.toolbar:visible([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description |
Get or set whether or not the toolbar is currently visible in the window it is attached to. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1133 |
Signature | hs.webview.toolbar:visibleItems() -> array |
---|---|
Type | Method |
Description |
Returns an array of the currently visible toolbar item identifiers. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview_toolbar.m line 1691 |
© 2014–2017 Hammerspoon contributors
Licensed under the MIT License.
https://www.hammerspoon.org/docs/hs.webview.toolbar.html