Documentation ¶
Overview ¶
Package alfred provides an API and various utility methods for creating Alfred workflows.
Index ¶
- Constants
- func CleanSplitN(s, sep string, n int) []string
- func FuzzyMatches(val string, test string) bool
- func FuzzySort(items []Item, test string)
- func IsDebugging() bool
- func LoadJSON(filename string, structure interface{}) error
- func RunScript(script string) (string, error)
- func SaveJSON(filename string, structure interface{}) error
- func SavePlist(filename string, p Plist)
- func SplitCmd(s string) (head, tail string)
- func Stringify(thing interface{}) string
- func TrimAllLeft(parts []string) []string
- type Action
- type ByTitle
- type Command
- type CommandDef
- type Filter
- type GitHubRelease
- type Item
- type ItemArg
- type ItemMod
- type Items
- type ModKey
- type ModeType
- type Plist
- type Workflow
- func (w *Workflow) AddPassword(name, password string) (err error)
- func (w *Workflow) AddUpdateItem(items *Items)
- func (w *Workflow) BundleID() string
- func (w *Workflow) CacheDir() string
- func (w *Workflow) DataDir() string
- func (w *Workflow) GetConfirmation(prompt string, defaultYes bool) (confirmed bool, err error)
- func (w *Workflow) GetInput(prompt, defaultVal string, hideAnswer bool) (button, value string, err error)
- func (w *Workflow) GetPassword(name string) (pw string, err error)
- func (w *Workflow) Name() string
- func (w *Workflow) Run(commands []Command)
- func (w *Workflow) SendToAlfred(items Items, data workflowData)
- func (w *Workflow) ShowMessage(message string) (err error)
- func (w *Workflow) UpdateAvailable() (release GitHubRelease, available bool)
- func (w *Workflow) UpdateAvailableNow() (release GitHubRelease, available bool)
- func (w *Workflow) Version() string
- func (w *Workflow) Website() string
- func (w *Workflow) WorkflowDir() string
Constants ¶
const ( // Line is an underline Line = "" /* 237-byte string literal not displayed */ // MinAlfredVersion is the minimum supported version of Alfred MinAlfredVersion = "3.1" )
Variables ¶
This section is empty.
Functions ¶
func CleanSplitN ¶
CleanSplitN trims leading and trailing whitespace from a string, splits it into at most N parts, and trims leading and trailing whitespace from each part
func FuzzyMatches ¶
FuzzyMatches returns true if val and test have a fuzzy match score != -1
func FuzzySort ¶
FuzzySort sorts an items list in-place based how well they match a given test string.
func IsDebugging ¶
func IsDebugging() bool
IsDebugging indicates whether an Alfred debug panel is open
func SplitCmd ¶
SplitCmd splits the initial word (a keyword) apart from the rest of an argument, returning the keyword (head) and the rest (tail). Whitespace is trimmed from both parts.
func Stringify ¶
func Stringify(thing interface{}) string
Stringify serializes a data object into a string suitable for including in an item Arg
func TrimAllLeft ¶
TrimAllLeft returns a copy of an array of strings in which space characters are trimmed from the left side of each element in the array.
Types ¶
type ByTitle ¶
type ByTitle Items
ByTitle is an array of Items which will be sorted by title.
type CommandDef ¶
type CommandDef struct { Keyword string Description string Mods map[ModKey]ItemMod IsEnabled bool Arg *ItemArg }
CommandDef describes a workflow command
func (*CommandDef) KeywordItem ¶
func (c *CommandDef) KeywordItem() (item Item)
KeywordItem creates a new Item for a command definition
type GitHubRelease ¶
type GitHubRelease struct { DataURL string `json:"url"` URL string `json:"html_url"` Name string `json:"name"` Prerelease bool `json:"prerelease"` Tag string `json:"tag_name"` Version semver.Version Created time.Time `json:"created_at"` Published time.Time `json:"published_at"` Assets []struct { URL string `json:"url"` Name string `json:"name"` DownloadURL string `json:"browser_download_url"` } `json:"assets"` }
GitHubRelease describes a project release on GitHub
type Item ¶
type Item struct { UID string Title string Subtitle string Autocomplete string Arg *ItemArg Icon string // contains filtered or unexported fields }
Item is an Alfred list item
func (*Item) AddCheckBox ¶
AddCheckBox modifies an Item to represent a selectable choice.
func (*Item) MarshalJSON ¶
MarshalJSON marshals an Item into JSON
type ItemArg ¶
type ItemArg struct { // Keyword specifies the destination keyword for this item Keyword string // Mode specifies what mode the keyword should operate in Mode ModeType // Data is the data string that will be passed to the target Command Data string }
ItemArg is an item argument
type Items ¶
type Items []Item
Items is a list of items
func InsertItem ¶
InsertItem inserts an item at a specific index in an array of Items.
func (Items) MarshalJSON ¶
MarshalJSON marshals a list of Items
type Workflow ¶
type Workflow struct { UpdateIcon string // contains filtered or unexported fields }
Workflow represents an Alfred workflow
func OpenWorkflow ¶
OpenWorkflow returns a Workflow for a given directory. If the createDirs option is true, cache and data directories will be created for the workflow.
func (*Workflow) AddPassword ¶
AddPassword adds or updates a password in the macOS Keychain
func (*Workflow) AddUpdateItem ¶
AddUpdateItem performs an update check and adds an update item to the given items list if one is available.
func (*Workflow) GetConfirmation ¶
GetConfirmation opens a confirmation dialog to ask the user to confirm something.
func (*Workflow) GetInput ¶
func (w *Workflow) GetInput(prompt, defaultVal string, hideAnswer bool) (button, value string, err error)
GetInput opens an input dialog to ask the user for some information.
func (*Workflow) GetPassword ¶
GetPassword returns a workflow-specific password from the macOS Keychain
func (*Workflow) Run ¶
Run runs a workflow.
A Workflow understands the following command line formats
$ ./workflow (arg|data) $ ./workflow arg data $ ./workflow -final data
Run takes one parameter: a list of Commands. Commands may be Filters or Actions. Filters are commands that generate lists of items, while Actions are commands that take an action.
When the mode is "tell"...
- ...and a keyword was specified in the incoming data, the Filter matching that keyword (if there is one) is called to generate items
- ...and no keyword was specified in the incoming data, items are generated for:
- any Filter with a fuzzy-matching keyword
- any Action with a fuzzy-matching keyword and an Arg in its CommandDef
func (*Workflow) SendToAlfred ¶
SendToAlfred sends an array of items to Alfred. Currently this equates to outputting an Alfred JSON message on stdout.
func (*Workflow) ShowMessage ¶
ShowMessage opens a message dialog to show the user a message.
func (*Workflow) UpdateAvailable ¶
func (w *Workflow) UpdateAvailable() (release GitHubRelease, available bool)
UpdateAvailable checks once a day whether a newer version of this workflow is available on GitHub.
func (*Workflow) UpdateAvailableNow ¶
func (w *Workflow) UpdateAvailableNow() (release GitHubRelease, available bool)
UpdateAvailableNow checks immediately whether a newer version of this workflow is available on GitHub.
func (*Workflow) WorkflowDir ¶
WorkflowDir returns a workflow's location.