Jump to content
Dwight

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

 

 

 

 

 

 

 

Share this post


Link to post

You appear to be trying to use an Apache command in PHP.

 

I don’t think you’ve quite understood how variables work. Here’s an article describing how to use them.

 

I don’t know the workflow you’re talking about, so I might be wrong, but I think you’ll have to change its “innards” if you want to set variables.

 

 

 

Share this post


Link to post

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.

Share this post


Link to post
Posted (edited)
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

Share this post


Link to post

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

 

Share this post


Link to post

In theory, you need to update the item-adding API to accept variables, and the XML-generation code to output them.

 

I can't say anything else, as the workflow has been taken down, and I don't have it.

Share this post


Link to post

Done. It was tricky because I do not know PHP but now its exactly working how I want it to 🙂

 

Thank you deanishe for your valuable help 👍

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...