launchbar

package module
v0.0.0-...-56b2b0b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2017 License: MIT Imports: 16 Imported by: 3

README

LaunchBar v6 helper for golang

Use this to quickly write LaunchBar v6 actions like a pro

The API has not been frozen yet.

Check these repos to see how to use this:

https://github.com/nbjahan/launchbar-pinboard
https://github.com/nbjahan/launchbar-spotlight

Docs:

http://godoc.org/github.com/nbjahan/go-launchbar

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

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheDoesNotExists = CacheError("the cache does not exists")
	ErrCacheIsCorrupted   = CacheError("the cache is corrupted")
	ErrCacheIsExpired     = CacheError("the cache is expired")
)
View Source
var AlwasMatch = func() bool { return true }

AlwaysMatch is a Matcher func that always returns true.

View Source
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.

View Source
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.

View Source
var NeverMatch = func() bool { return false }

NeverMatch is a Matcher func that always returns false.

View Source
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

func (a *Action) ActionPath() string

ActionPath returns the absolute path to the .lbaction bundle.

func (*Action) CachePath

func (a *Action) CachePath() string

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) GetItem

func (a *Action) GetItem(id int) *Item

GetItem return an Item with its ID. Returns nil if not found.

func (*Action) GetView

func (a *Action) GetView(v string) *View

GetView returns a View if the view is not defined returns nil

func (*Action) InDev

func (a *Action) InDev() bool

InDev returns true if the config.indev is true

func (*Action) Init

func (a *Action) Init(m ...FuncMap) *Action

Init parses the input

func (*Action) IsBackground

func (a *Action) IsBackground() bool

IsBackground returns true if the action is running in background.

func (*Action) IsCommandKey

func (a *Action) IsCommandKey() bool

IsCommandKey returns true if the Command key was down while running the action.

func (*Action) IsControlKey

func (a *Action) IsControlKey() bool

IsControlKey returns true if the Control key was down while running the action.

func (*Action) IsDebug

func (a *Action) IsDebug() bool

IsDebug returns the value corresponds to LBDebugLogEnabled in the action’s Info.plist.

func (*Action) IsOptionKey

func (a *Action) IsOptionKey() bool

IsOptionKey returns true if the Alternate (Option) key was down while running the action.

func (*Action) IsShiftKey

func (a *Action) IsShiftKey() bool

IsShiftKey returns true if the Shift key was down while running the action.

func (*Action) LaunchBarPath

func (a *Action) LaunchBarPath() string

Launchbarpath returns the path to the LaunchBar.app bundle.

func (*Action) NewView

func (a *Action) NewView(name string) *View

NewView created a new view ready to populate with Items

func (*Action) Run

func (a *Action) Run() string

Run returns the compiled output of views. You must call Init first

func (*Action) ScriptType

func (a *Action) ScriptType() string

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

func (a *Action) ShowView(v string)

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

func (a *Action) SupportPath() string

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.

func (*Action) Version

func (a *Action) Version() Version

Varsion returns Action version specified by CFBundleVersion key in Info.plist

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides tools for non permanent storage

func NewCache

func NewCache(p string) *Cache

NewCache initialize and returns a new Cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes a cachefile for the specified key

func (*Cache) Get

func (c *Cache) Get(key string, v interface{}) (*time.Time, error)

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) GetItems

func (c *Cache) GetItems(key string) *Items

GetItems is a helper function to get the stored items from the cache

func (*Cache) GetItemsWithInfo

func (c *Cache) GetItemsWithInfo(key string) (*Items, *time.Time, error)

GetItemsWithInfo is a helper function to get the stored items from the caceh with the expiry time and error

func (*Cache) Set

func (c *Cache) Set(key string, data interface{}, d time.Duration)

Set stores the data in a file identified by the key and with the lifetime of d

func (*Cache) SetItems

func (c *Cache) SetItems(key string, items *Items, d time.Duration)

SetItems is a helper function to store some Items

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 NewConfig

func NewConfig(p string) *Config

NewConfig initializes an new Config object with the specified path and returns it.

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) Delete

func (c *Config) Delete(keys ...string)

Delete removes the key from config file.

func (*Config) Get

func (c *Config) Get(key string) interface{}

Get gets the value from config for the key

func (*Config) GetBool

func (c *Config) GetBool(key string) bool

GetBool gets the value from config for the key as bool

func (*Config) GetFloat

func (c *Config) GetFloat(key string) float64

GetFloat gets the value from config for the key as float64

func (*Config) GetInt

func (c *Config) GetInt(key string) int64

GetInt gets the value from config for the key as int64

func (*Config) GetString

func (c *Config) GetString(key string) string

GetString gets the value from config for the key as string

func (*Config) GetTimeDuration

func (c *Config) GetTimeDuration(key string) time.Duration

GetTimeDuration gets the value from config for the key as time.Duration

func (*Config) Set

func (c *Config) Set(key string, val interface{})

Set sets the key, val and saves the config to the disk.

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 Func

type Func interface{}

Func represents a generic type to pass functions.

type FuncMap

type FuncMap map[string]Func

FuncMap represents a predefined map of functions to execute with Item.Run

type Input

type Input struct {
	Item *Item
	// contains filtered or unexported fields
}

Input represents the object that LaunchBar passes to scripts

func NewInput

func NewInput(a *Action, args []string) *Input

func (*Input) Data

func (in *Input) Data(key string) interface{}

func (*Input) DataInt

func (in *Input) DataInt(key string) int

DataInt returns a customdata[key] as string

func (*Input) DataString

func (in *Input) DataString(key string) string

DataString returns a customdata[key] as string

func (*Input) Float64

func (in *Input) Float64() float64

func (*Input) FuncArg

func (in *Input) FuncArg() string

func (*Input) FuncArgs

func (in *Input) FuncArgs() map[int]string

func (*Input) FuncArgsMapString

func (in *Input) FuncArgsMapString() map[int]string

TODO: Deprecated use FuncArgs

func (*Input) FuncArgsString

func (in *Input) FuncArgsString() []string

TODO: Deprecated use FuncArgs

func (*Input) Int

func (in *Input) Int() int

func (*Input) Int64

func (in *Input) Int64() int64

func (*Input) IsEmpty

func (in *Input) IsEmpty() bool

func (*Input) IsFloat

func (in *Input) IsFloat() bool

func (*Input) IsInt

func (in *Input) IsInt() bool

func (*Input) IsLiveFeedback

func (in *Input) IsLiveFeedback() bool

FIXME: experimental

func (*Input) IsNumber

func (in *Input) IsNumber() bool

func (*Input) IsObject

func (in *Input) IsObject() bool

func (*Input) IsPaths

func (in *Input) IsPaths() bool

func (*Input) IsString

func (in *Input) IsString() bool

func (*Input) Paths

func (in *Input) Paths() []string

func (*Input) Raw

func (in *Input) Raw() string

func (*Input) String

func (in *Input) String() string

func (*Input) Title

func (in *Input) Title() string

type Item

type Item struct {
	View *View
	// contains filtered or unexported fields
}

Item represents the LaunchBar item

func NewItem

func NewItem(title string) *Item

NewItem initialize and returns a new Item

func (*Item) Done

func (i *Item) Done() *View

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

func (i *Item) Run(f string, args ...interface{}) *Item

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

func (i *Item) SetAction(action string) *Item

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

func (i *Item) SetActionArgument(arg string) *Item

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

func (i *Item) SetActionBundleIdentifier(s string) *Item

SetActionBundleIdentifier sets the identifier of an action that should be run when the user selects this item and hits enter

func (*Item) SetActionReturnsItems

func (i *Item) SetActionReturnsItems(b bool) *Item

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

func (i *Item) SetActionRunsInBackground(b bool) *Item

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

func (i *Item) SetChildren(items *Items) *Item

SetChildren sets an array of items.

func (*Item) SetIcon

func (i *Item) SetIcon(icon string) *Item

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

func (i *Item) SetMatch(fn Func) *Item

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

func (i *Item) SetOrder(n int) *Item

SetOrder sets the order of the item. The Items are ordered by their creation time.

func (*Item) SetPath

func (i *Item) SetPath(path string) *Item

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

func (i *Item) SetQuickLookURL(qlurl string) *Item

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

func (i *Item) SetRender(fn Func) *Item

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

func (i *Item) SetRun(fn Func) *Item

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

func (i *Item) SetSubtitle(subtitle string) *Item

SetSubtitle sets the Item's subtitle that appears below or next to the title.

func (*Item) SetTitle

func (i *Item) SetTitle(title string) *Item

SetTitle sets the Item's title.

func (*Item) SetURL

func (i *Item) SetURL(url string) *Item

SetURL sets the Item's URL. When the user selects the item and hits Enter, this URL is opened.

type Items

type Items []*Item

Items represents the collection of items

func NewItems

func NewItems() *Items

NewItems creates an empty Items collection

func (*Items) Add

func (items *Items) Add(i ...*Item) *Items

Add adds passes Items to the collection and returns the collection.

func (*Items) Compile

func (items *Items) Compile() string

Compile returns items collection as a json string.

type Version

type Version string

Version represents a version string (e.g. 1.0, 1.0, 1.0.0)

func (Version) Cmp

func (v Version) Cmp(w Version) int

Cmp compares v and w and returns

-1 if v < w
0 if v == w
+1 if v > w

func (Version) Equal

func (v Version) Equal(w Version) bool

Equal returns true if v == w Example:

Version("1.0").Equal(Version("1")) == true

func (Version) Less

func (v Version) Less(w Version) bool

Less returns true if v < w Example:

Version("0.1.0").Less(Version("1.0")) == true

type View

type View struct {
	Action *Action
	Name   string
	Items  Items
}

View represents collection of Items in LaunchBar

func (*View) AddItem

func (v *View) AddItem(item *Item) *View

AddItem add an Item to the view

func (*View) Compile

func (v *View) Compile() string

Compile renders and output the view.Items as a json string.

func (*View) Join

func (v *View) Join(w *View) *View

Join returns a new view with the items of v, w

func (*View) NewItem

func (v *View) NewItem(title string) *Item

NewItem creates an always matching Item that runs in background and adds it to the view.

func (*View) Render

func (v *View) Render() Items

Render executes each Item Render, Match functions and returns them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL