Documentation ¶
Overview ¶
Package launchbar is a package to quickly write LaunchBar v6 actions like a pro
For example check :
https://github.com/nbjahan/launchbar-pinboard https://github.com/nbjahan/launchbar-spotlight
Index ¶
- Variables
- type Action
- func (a *Action) ActionPath() string
- func (a *Action) CachePath() string
- func (a *Action) GetItem(id int) *Item
- func (a *Action) GetView(v string) *View
- func (a *Action) InDev() bool
- func (a *Action) Init(m ...FuncMap) *Action
- func (a *Action) IsBackground() bool
- func (a *Action) IsCommandKey() bool
- func (a *Action) IsControlKey() bool
- func (a *Action) IsDebug() bool
- func (a *Action) IsOptionKey() bool
- func (a *Action) IsShiftKey() bool
- func (a *Action) LaunchBarPath() string
- func (a *Action) NewView(name string) *View
- func (a *Action) Run() string
- func (a *Action) ScriptType() string
- func (a *Action) ShowView(v string)
- func (a *Action) SupportPath() string
- func (a *Action) Version() Version
- type Cache
- func (c *Cache) Delete(key string)
- func (c *Cache) Get(key string, v interface{}) (*time.Time, error)
- func (c *Cache) GetItems(key string) *Items
- func (c *Cache) GetItemsWithInfo(key string) (*Items, *time.Time, error)
- func (c *Cache) Set(key string, data interface{}, d time.Duration)
- func (c *Cache) SetItems(key string, items *Items, d time.Duration)
- type CacheError
- type Config
- func (c *Config) Delete(keys ...string)
- func (c *Config) Get(key string) interface{}
- func (c *Config) GetBool(key string) bool
- func (c *Config) GetFloat(key string) float64
- func (c *Config) GetInt(key string) int64
- func (c *Config) GetString(key string) string
- func (c *Config) GetTimeDuration(key string) time.Duration
- func (c *Config) Set(key string, val interface{})
- type ConfigValues
- type Context
- type Func
- type FuncMap
- type Input
- func (in *Input) Data(key string) interface{}
- func (in *Input) DataInt(key string) int
- func (in *Input) DataString(key string) string
- func (in *Input) Float64() float64
- func (in *Input) FuncArg() string
- func (in *Input) FuncArgs() map[int]string
- func (in *Input) FuncArgsMapString() map[int]string
- func (in *Input) FuncArgsString() []string
- func (in *Input) Int() int
- func (in *Input) Int64() int64
- func (in *Input) IsEmpty() bool
- func (in *Input) IsFloat() bool
- func (in *Input) IsInt() bool
- func (in *Input) IsLiveFeedback() bool
- func (in *Input) IsNumber() bool
- func (in *Input) IsObject() bool
- func (in *Input) IsPaths() bool
- func (in *Input) IsString() bool
- func (in *Input) Paths() []string
- func (in *Input) Raw() string
- func (in *Input) String() string
- func (in *Input) Title() string
- type Item
- func (i *Item) Done() *View
- func (i *Item) Item() *item
- func (i *Item) Run(f string, args ...interface{}) *Item
- func (i *Item) SetAction(action string) *Item
- func (i *Item) SetActionArgument(arg string) *Item
- func (i *Item) SetActionBundleIdentifier(s string) *Item
- func (i *Item) SetActionReturnsItems(b bool) *Item
- func (i *Item) SetActionRunsInBackground(b bool) *Item
- func (i *Item) SetChildren(items *Items) *Item
- func (i *Item) SetIcon(icon string) *Item
- func (i *Item) SetMatch(fn Func) *Item
- func (i *Item) SetOrder(n int) *Item
- func (i *Item) SetPath(path string) *Item
- func (i *Item) SetQuickLookURL(qlurl string) *Item
- func (i *Item) SetRender(fn Func) *Item
- func (i *Item) SetRun(fn Func) *Item
- func (i *Item) SetSubtitle(subtitle string) *Item
- func (i *Item) SetTitle(title string) *Item
- func (i *Item) SetURL(url string) *Item
- type Items
- type Version
- type View
Constants ¶
This section is empty.
Variables ¶
var ( ErrCacheDoesNotExists = CacheError("the cache does not exists") ErrCacheIsCorrupted = CacheError("the cache is corrupted") ErrCacheIsExpired = CacheError("the cache is expired") )
var AlwasMatch = func() bool { return true }
AlwaysMatch is a Matcher func that always returns true.
var MatchIfFalseFunc = func(b bool) func() bool { return func() bool { return !b } }
MatchIfFalseFunc is Matcher func that returns true a value of passes argument is false.
var MatchIfTrueFunc = func(b bool) func() bool { return func() bool { return b } }
MatchIfTrueFunc is Matcher func that returns true if a value of passed argument is true.
var NeverMatch = func() bool { return false }
NeverMatch is a Matcher func that always returns false.
var ShowViewFunc = func(v string) func(*Context) { return func(c *Context) { c.Action.ShowView(v) } }
ShowViewFunc is a Runner func that shows the specified view.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { inject.Injector // Used for dependency injection Config *Config Cache *Cache Input *Input Logger *log.Logger // contains filtered or unexported fields }
Action represents a LaunchBar action
func NewAction ¶
func NewAction(name string, config ConfigValues) *Action
NewAction creates an empty action, ready to populate with views
func (*Action) ActionPath ¶
ActionPath returns the absolute path to the .lbaction bundle.
func (*Action) CachePath ¶
CachePath returns the absolute path to the action’s cache directory:
~/Library/Caches/at.obdev.LaunchBar/Actions/Action Bundle Identifier/
The action’s cache directory can be used to store files that can be recreated by the action itself, e.g. by downloading a file from a server again.
Currently, this directory’s contents will never be touched by LaunchBar, but it may be periodically cleared in a future release. When the action is run, this directory is guaranteed to exist.
func (*Action) IsBackground ¶
IsBackground returns true if the action is running in background.
func (*Action) IsCommandKey ¶
IsCommandKey returns true if the Command key was down while running the action.
func (*Action) IsControlKey ¶
IsControlKey returns true if the Control key was down while running the action.
func (*Action) IsDebug ¶
IsDebug returns the value corresponds to LBDebugLogEnabled in the action’s Info.plist.
func (*Action) IsOptionKey ¶
IsOptionKey returns true if the Alternate (Option) key was down while running the action.
func (*Action) IsShiftKey ¶
IsShiftKey returns true if the Shift key was down while running the action.
func (*Action) LaunchBarPath ¶
Launchbarpath returns the path to the LaunchBar.app bundle.
func (*Action) ScriptType ¶
ScriptType returns the type of the script, as defined by the action’s Info.plist.
This is either “default”, “suggestions” or “actionURL”.
See http://www.obdev.at/resources/launchbar/developer-documentation/action-programming-guide.html#script-types for more information.
func (*Action) ShowView ¶
ShowView reruns the LaunchBar with the specified view.
Use this when your LiveFeedback is enabled and you want to show another view
func (*Action) SupportPath ¶
Supportpath returns the The absolute path to the action’s support directory:
~/Library/Application Support/LaunchBar/Action Support/Action Bundle Identifier/
The action support directory can be used to persist user data between runs of the action, like preferences. When the action is run, this directory is guaranteed to exist.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides tools for non permanent storage
func (*Cache) Get ¶
Get the data from cachefile specified by the key and stores it into the value pointed to by v
if the cache does not exists it returns nil, ErrCacheDoesNotExists
if the cache is expired it returns the expire time and ErrCacheIsExpired
if there's an error reading the cachefile it returns nil, ErrCacheIsCorrupted
Otherwise it returns the expiry time, nil
func (*Cache) GetItemsWithInfo ¶
GetItemsWithInfo is a helper function to get the stored items from the caceh with the expiry time and error
type CacheError ¶
type CacheError string
func (CacheError) Error ¶
func (c CacheError) Error() string
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config provides permanent config utils for the action.
func NewConfigDefaults ¶
func NewConfigDefaults(p string, defaults ConfigValues) *Config
NewConfigDefaults initializes a new Config object with the specified path and default values and returns it.
func (*Config) GetTimeDuration ¶
GetTimeDuration gets the value from config for the key as time.Duration
type ConfigValues ¶
type ConfigValues map[string]interface{}
ConfigValues represents a Config values
type Context ¶
type Context struct { Action *Action // points to the LaunchBar action Config *Config // the Config object Cache *Cache // the Cache object Self *Item // the item that is accessing the context Input *Input // the user input Logger *log.Logger // Logger is used to log to Action.SupportPath() + '/error.log' }
Context is a dependency that is available in Matcher, Runner, Renderer func
type Input ¶
type Input struct { Item *Item // contains filtered or unexported fields }
Input represents the object that LaunchBar passes to scripts
func (*Input) DataString ¶
DataString returns a customdata[key] as string
func (*Input) FuncArgsMapString ¶
TODO: Deprecated use FuncArgs
func (*Input) FuncArgsString ¶
TODO: Deprecated use FuncArgs
type Item ¶
type Item struct { View *View // contains filtered or unexported fields }
Item represents the LaunchBar item
func (*Item) Done ¶
Done returns the pointer to the Item's view, used for chaining the item creation.
func (*Item) Item ¶
func (i *Item) Item() *item
Item returns an underlying LaunchBar item that can be passed around in json format.
func (*Item) Run ¶
Run sets the predefined func (see FuncMap) to be run with the optional arguments when the user selects this item and hit Enter
func (*Item) SetAction ¶
SetAction sets the name of an action that should be run when the user selects this item and hits Enter. This is the name of a script file inside the action bundle’s Scripts folder, including the file name extension.
The argument for the action depends on the value of actionArgument.
func (*Item) SetActionArgument ¶
SetActionArgument sets the argument to pass to the action.
When the user selects this item and hits Enter and the item has an action set, this is the argument that gets passed to that action as a string. If this key is not present, the whole item is passed as an argument as a JSON string
func (*Item) SetActionBundleIdentifier ¶
SetActionBundleIdentifier sets the identifier of an action that should be run when the user selects this item and hits enter
func (*Item) SetActionReturnsItems ¶
SetActionReturnsItems specifies that selecting and executing the item (as specified by the action key) will return a new list of items. If this is set to true, the item will have a chevron on the right side indicating that the user can navigate into it and doing so causes action to be executed.
func (*Item) SetActionRunsInBackground ¶
SetActionRunsInBackground sets the action to be run in background
See http://www.obdev.at/resources/launchbar/developer-documentation/action-info-plist.html#info-plist-LBRunInBackground for more detail.
func (*Item) SetChildren ¶
SetChildren sets an array of items.
func (*Item) SetIcon ¶
SetIcon sets the icon for the item. This is a string that is interpreted the same way as CFBundleIconFile in the action’s Info.plist.
http://www.obdev.at/resources/launchbar/developer-documentation/action-info-plist.html#info-plist-CFBundleIconFile
func (*Item) SetMatch ¶
SetMatch sets the matcher func of this item. This func determines that if the item should be visible or not.
Example:
func(c *Context) bool { return c.Action.IsControlKey() }
func (*Item) SetOrder ¶
SetOrder sets the order of the item. The Items are ordered by their creation time.
func (*Item) SetPath ¶
SetPath sets the absolute path of a file or folder the item represents. If icon is not set, LaunchBar automatically uses an item that represents the path.
func (*Item) SetQuickLookURL ¶
SetQuickLookURL sets the URL to be shown by the QuickLook panel when the user hits ⌘Y on the item. This can by any URL supported by QuickLook, including http of file URLs. Items that have a path property automatically support QuickLook and do not need to set this property too.
func (*Item) SetRender ¶
SetRender sets the renderer func of this item. This func will be executed each time the user enters a key and can be used to update the values based on the user input. Example:
func(c *Context) { c.Self.SetSubtitle("") }
func (*Item) SetRun ¶
SetRun sets the runner func of this item. This func is optional and will be run when the user selects the item and hit Enter. Runner func output is optional, if it returns Items those items will be displayed to the user.
Example:
func(c *Context) { c.Action.ShowView("main") }
func (*Item) SetSubtitle ¶
SetSubtitle sets the Item's subtitle that appears below or next to the title.
type Items ¶
type Items []*Item
Items represents the collection of items
type Version ¶
type Version string
Version represents a version string (e.g. 1.0, 1.0, 1.0.0)
type View ¶
View represents collection of Items in LaunchBar