Jump to content

How to assign values to an environment variable within php scripts?


Recommended Posts

Hello all,

 

I defined a variable "input" as Workflow Environment Variable in a workflow. Especially it is the "Leo Dictionary" workflow from Bastian Ohmer. The script in the script filter is:

 require('leo.php');

 $in = "{query}";
 $leo = new Leo("ende");
 echo $leo->getTranslations($in);

 

with Language: /usr/bin/php, "with input as {query}" and as Escaping "Double Quotes" and "Dollars".

 

I would like to assign "{query}"  to my my "input" environment variable in order to be able to use it after the script filter in other action modifiers.

 

Everything I tried failed. E.g.:

 require('leo.php');

 $in = "{query}";
 SetEnv $input $in;
 $leo = new Leo("ende");
 echo $leo->getTranslations($in);

 

==> Code 254: Parse error: syntax error, unexpected '$input' (T_VARIABLE) in Command line code on line 4

 

Any ideas how to solve it?

 

Thank you very much

 

 

 

 

 

 

 

Link to comment

Thank you for the help. I now understood that I have to output a certain JSON in order to assign values to environment variables.

 

I did not really understood the Leo workflow but I assume you are right: Probably the PHP code itself must be changed. Will try to figure it out some day later.

Link to comment
2 hours ago, Dwight said:

Probably the PHP code itself must be changed.

 

If it’s a Script Filter, then yes, you’ll definitely have to change the PHP code, but nothing massive (hopefully).

 

If you post a link to the workflow you’re talking about, I (or someone who really knows PHP) could point you in the right direction.

Edited by deanishe
Link to comment

Ok, thank you.

 

The workflow is called Leo Dictionary and you can find it on https://github.com/psistorm/alfredapp

 

What I figured out so far:

  • The Script Filter is using a script leo.php
  • leo.php is using a function toxml() of workflow.php to generate an XML file
  • toxml() is mainly generating an item list
  • Alfred comes with an Advanced Script Filters example workflow and the script filter called xvar is giving an example of how to work with variables

==> In my opinion it should work if the toxml() function will be extended in such a way, that it also puts the variable I need into the XML file. This would be a kind of dirty approach but on the other hand the Leo workflow is not under development anymore and XML is deprecated. So, it would not make to much sense to put a lot of effort into changes.

 

I do not know PHP neither but I have the impression this "hack" could not to be that complicated

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...