Jump to content

How to pass script result to display in XML format as action


Recommended Posts

Hi everyone!

 

I'm new to Alfred, not a coder but have adapted a few extensions to suit my needs.

 

I'm not wanting to do a simple (or not) thing:

 

1. use keyword as a trigger

2. take {query} and pass it to a script (say a php one which echo's the result)

3. take this result and display it as a result which can then be actioned (probably copied).

 

I've looked at the existing examples which use xmlformat (particularly the google autocomplete one) and at the xmlformat example provided but I'm still struggling.

 

So, I thought I need a basic building block to understand how this might work.

 

e.g.

 

1. trigger keyword: test, argument required

2. pass {query} to php script which does something basic with it e.g.

 

$query = "{query}";

echo $query;

 

then take THIS result and display it in XMLformat for Alfred to show in results. I can't for the life of me work out how to do that!

 

Can anyone help? It's driving me mad!

 

Thank you!

Link to comment

In order to generate results that show in Alfred and action them you don't use a keyword, you use a Script Filter. That could be one thing that's tripping you up. Also, once something is actioned, you can't generate more results to be shown. Things like this may come in the future but you can only use one Script Filter right now unless you create a separate one and use AppleScript to loop back to it.

Link to comment

Thanks for that. I'm stll struggling though (perhaps cause I'm not a coder but eager to learn).

 

So I've created a script filter with argument required, selected php as the script language and put this (adapted from another workflow):

 

require_once('extension_utils.php');
$utils = new ExtensionUtils();

$query = "{query}";
	$item = array(
		'uid' => 'suggest ',
		'arg' => 'jffk',
		'title' => 'kdfkjd',
		'subtitle' => 'Search Amazon UK for ',
		'icon' => 'icon.png',
		'valid' => 'yes'
	);

	echo $utils->arrayToXml($item);

 

If my understanding is right then the above creates the $item array and passes it to extension utils to create xml.

 

Then I'm linking this to output {query} to clipboard.

 

So when I open alfred and type "test myquery" and press enter nothing happens. From all the other examples I've looked at I should be seeing a list of the static elements inside $item, shouldn't I?

 

Thanks

Link to comment

Thanks for that. I'm stll struggling though (perhaps cause I'm not a coder but eager to learn).

 

So I've created a script filter with argument required, selected php as the script language and put this (adapted from another workflow):

 

require_once('extension_utils.php');
$utils = new ExtensionUtils();

$query = "{query}";
	$item = array(
		'uid' => 'suggest ',
		'arg' => 'jffk',
		'title' => 'kdfkjd',
		'subtitle' => 'Search Amazon UK for ',
		'icon' => 'icon.png',
		'valid' => 'yes'
	);

	echo $utils->arrayToXml($item);

 

If my understanding is right then the above creates the $item array and passes it to extension utils to create xml.

 

Then I'm linking this to output {query} to clipboard.

 

So when I open alfred and type "test myquery" and press enter nothing happens. From all the other examples I've looked at I should be seeing a list of the static elements inside $item, shouldn't I?

 

Thanks

 

Not when you press Enter. Script filters begin firing as soon as you start entering data. So in this case, as soon as you started typing "myquery" it would run the script.

 

Now.. ExtensionUtils was something I created a while back. I have updated it and it is now just called Workflows. The usage for it varies a little but the same basic concepts apply. You could still use extensionutils if you wanted to but my question at this point is, is that php script in your workflow folder? It's not something built into PHP, its a library that I created and included in some of my older workflows.

Link to comment

Oh! Okay. extensionutils was definitely in the folder (one of the first things I checked) but icon.png wasn't so maybe that was throwing it off.I'm not sure, I've now used workflows.php and it works fine BUT the result doesn't seem actionable.

 

I just want the chosen result copied to clipboard so I have the script filter linked to output cop {query} to clipboard. One thing that's not clear to me in Workflows is whether the {query} passed to output is the original {query} or the one processed by the previous step in the workflow?

 

Many thanks for your help!

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...