Copyright | (c) 2014 Patrick Bahr |
---|---|
License | BSD3 |
Maintainer | Patrick Bahr <paba@di.ku.dk> |
Stability | experimental |
Portability | non-portable (GHC Extensions) |
Safe Haskell | None |
Language | Haskell98 |
This module provides utility functions to interact with Alfred version 2. It is intended to be used for writing "script filters" used in Alfred workflows.
For example the following excerpt defines a script for Google search with auto completion:
import Alfred import Alfred.Query import qualified Data.Text as T import Data.Text (Text) runQuery :: Query (Text,[Text]) runQuery = jsonQuery suggestURL suggestURL = "http://google.com/complete/search?client=firefox&q=" mkItems :: Renderer [Text] mkItems = searchRenderer Search { searchURL = s -> T.concat ["https://www.google.com/search?q=", s], notFound = s -> T.concat ["No suggestion. Google for ", s, "."], found = s -> T.concat ["Search results for ", s]} main = runScript (transformQuery snd runQuery) mkItems
- data Item = Item {}
- item :: Item
- data Icon
- type Renderer a = Renderer' Text a
- type Renderer' q a = q -> Either Text a -> Items
- runScript :: Query a -> Renderer a -> IO ()
- runScript' :: ([Text] -> q) -> Query' q a -> Renderer' q a -> IO ()
- searchRenderer :: Search Text -> Renderer [Text]
- searchRenderer' :: Search' a -> Renderer [a]
- data Search a = Search {}
- data Search' a = Search' {
- simpleSearch :: Search a
- resultURL :: a -> Text
- resultTitle :: a -> Text
Documentation
This type represents items that should be rendered by Alfred as the result of a script filter.
type Renderer a = Renderer' Text a Source
This type represents rendering functions as used by runScript
.
type Renderer' q a = q -> Either Text a -> Items Source
This type represents rendering functions as used by runScript'
.
This function runs a script consisting of a query function and a rendering function. The query function takes string parameters and produces an output that is then passed to the rendering function to produce items that are then passed to Alfred.
This function runs a script consisting of a query function and a rendering function. The query function takes string parameters and produces an output that is then passed to the rendering function to produce items that are then passed to Alfred.
searchRenderer :: Search Text -> Renderer [Text] Source
This function produces a rendering function for standard search scripts. For example a Google search rendering function is defined as follows:
mkItems :: Renderer [Text] mkItems = searchRenderer Search { searchURL = s -> T.concat ["https://www.google.com/search?q=", s], notFound = s -> T.concat ["No suggestion. Google for ", s, "."], found = s -> T.concat ["Search results for ", s]}
searchRenderer' :: Search' a -> Renderer [a] Source
This function produces a rendering function for standard search
scripts. As opposed to the simpler variant searchRenderer
, this
function works on arbitrary query result types. For example a DBLP
search rendering function is defined as follows:
mkItems :: Renderer [(Text, Text)] mkItems = searchRenderer' Search'{ simpleSearch = Search { searchURL = s -> T.concat ["http://dblp.uni-trier.de/search/author?author=", s], notFound = s -> T.concat ["No suggestion. Search DBLP for ", s, "."], found = (s,_) -> T.concat ["Open bibliography of ", s]}, resultURL = (_,r) -> T.concat ["http://dblp.uni-trier.de/pers/hd/",r,".html"], resultTitle = fst}
In the above example the query result type is (Text,Text)
where
the first component is the name of the result and the second
component is used to construct a URL that leads directly to the
search result.
This data type represents standard search scripts used by
searchRenderer
.
This data type represents advanced standard search scripts used
by searchRenderer'
.
Search' | |
|