Download the PHP package dpeuscher/alfred-symfony-tools without Composer
On this page you can find all versions of the php package dpeuscher/alfred-symfony-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package alfred-symfony-tools
- alfred-symfony-tools
- Autocomplete Lists
- Hard coded argument-lists
- Dynamically loaded argument-lists
- Execution operations
- ConfigureCommand
- DotEnvEditor
- Alfred Workflow
- alfred.php
- Creating the workflow
- Tips
- Environment variables
- Config command
- Example
- Autocomplete Lists
alfred-symfony-tools
Toolkit for integrating Alfred workflows with Symfony4 Frameworks Commands
This toolkit helps if you want to use the Symfony Command-Structure with Alfred workflows. You can easily add ways to autocomplete parameters without thinking too much about the idea that Alfred workflows will start a new process everytime you type something. Also there is a Command that you can extend from to allow you setting .env-Parameters via Alfred.
Autocomplete Lists
To provide the user of your Alfred workflow with an easy way to navigate through his options, you have to provide a list of allowed values for your arguments. With that the user can easily walk through all options with the Alfred interface.
To create a Command that is capable of this, you need to extend from either or . You have then the ability to either define the allowed values while defining the argument in the -method (good for static arguments, whose values are hardcoded) or later in the -method of the Command.
Hard coded argument-lists
You can see that it is possible to use numeric or associative option-lists. If you use numeric lists (arg1), the selector willbe defined automatically by the first combination of words that identify your option. For associative lists (arg2) the keys will be used as identifier. You can allow to add selections that are not in the list by setting the -parameter to true (arg3). Also it is possible that you mix autocomplete-arguments with general ones (arg4, arg5).
Dynamically loaded argument-lists
Since the container is not available in the -method, you might want to add options in the -method from parameters that are set in the config or .env file. You can to that with the -method that also supports the -parameter.
Execution operations
Now you want to be able to handle different inputs differently. There are predefined input-handlers for the autocomplete arguments, but you can easily override them with the -method. Just define for which set of arguments you want to define a handler and define it. The handler itself can be a closure or a method within the Command-class. It gets an array of the given variables and possible autocomplete-values and the result of the generic result as a parameter so you can get started pretty quick in changing the result. If you don't return something it will default to the (possibly aligned) genericResult-entry from the arguments-array.
To set the titles of the options of arg3 to have a leading uppercase letter when you had selected option1 as arg1 you could do something like this:
The order of the parameters matters. in the upper example will never match!
The -class is only a representation for the format of the Alfred workflow json definition. It supports the following method:
- uid
- title
- subtitle
- quicklookurl
- type
- valid
- icon
- autocomplete
- largetype
- arg
- copy
To understand their meaning please look into the Alfred documentation. As an addition, if you provide a url as an icon, will copy it to your tmp folder (that you can change in the constructor), formats it and uses it, since Alfred itself can only handle local images.
ConfigureCommand
To use the ConfigureCommand to write data into your .env-file you have to extend it in your commands-folder to make it dispatchable. You then have to define which Variables you want to be able to change via Alfred and define them in your configuration at the key . It should be a numeric array, that has the names of the variables as values. If you want to define an array, add behind its name.
You can then set these values if you call the route in your application.
DotEnvEditor
To use the ConfigureCommand you have to create a special config, that has be to named dotenveditor.php and should be in your config/-folder. If you want to set it somewhere else you can do so by setting the config parameter configDotEnvFileConfiguration to the path where it can be found. the file needs to return an array with at least the key that links to your .env-file. You can optionally provide a for backups. An example file for the default configuration would be:
config/dotenveditor.php:
Alfred Workflow
alfred.php
To properly work, you need a special alfred-bin file. It should not have the shebang-line of the bin/console script in it, because that would break the valid json-output. Therefor the easiest way would be to copy the bin/console to bin/alfred.php. You can also use the provided alfred.php in the example-folder of this repository.
To have a proper escaping, you should add these lines underneath the use-statements of the console-file (the alfred.php in the examples folder has it already):
Creating the workflow
You create a new Alfred workflow by clicking on the "+" in the bottom bar and select "Blank Workflow". After that, select your workflow and right click into the empty space, click on "Input" and select "Script Filter". Double-click the "Script Filter" item on the page and define a placeholder. Configure the placeholder-stuff as you like. Use the following script to have the dispatching working:
You have to select "/usr/bin/php" as Language, "with input as {query}", tick "Double Quotes", "Backslashes" and "Dollars" in the "Escaping"-Selection on the bottom.
Replace the "command" in the script and keyword section by the command you want to have
Tips
Environment variables
The output commands can use variables, that you pass in the -method of the -Class to work with it. You can access it in the command as a protected parameter :
In the connected script, you can access it by calling environment variables. Here are a few ways to access:
-
Applescript
-
Bash
- PHP
Config command
Activate "Argument Optional" instead of "Argument Required". The script for the config looks like this:
It is connected to a "Run Script" item with the following script:
The rest of the settings of the "Run Script" should look like the "Script Input" item.
Example
Find a proof-of-concept here: dpeuscher/alfred-movie-rating
License
All versions of alfred-symfony-tools with dependencies
ext-ctype Version *
ext-iconv Version *
symfony/framework-bundle Version ^4.0
joetannenbaum/alfred-workflow Version ^0.1.1
symfony/console Version ^4.1
monolog/monolog Version ^1.23
makbari/dot-env-editor Version ^0.1.4
symfony/yaml Version ^4.1
symfony/dotenv Version ^4.1