Jump to content

REQUEST: Intro to Workflow Programming


Recommended Posts

Hi,

 

I was wondering if anyone was willing to write up an intro to workflow programming? I see it accepts a lot of languages, and I know PHP/MySQL, Ruby, some Ojective-C and whatnot, but I don't know how to leverage those languages to interact with Alfred in a workflow.

 

Any help or recommendations you have for getting started with programming some more complex workflows are appreciated.

Link to comment

Hi,

I was wondering if anyone was willing to write up an intro to workflow programming? I see it accepts a lot of languages, and I know PHP/MySQL, Ruby, some Ojective-C and whatnot, but I don't know how to leverage those languages to interact with Alfred in a workflow.

Any help or recommendations you have for getting started with programming some more complex workflows are appreciated.

Most would agree that the workflows and extensions I've created in the past have some of the most elaborate ones created. The majority of mine are created in PHP and bash scripts. While I don't have a tutorial (may try to make a simple screencast soon) but I am available to help you with anything you could possibly need. I've got a workflows library I've created for php that allows you easily do things and provide feedback into Alfred as well.

Basically, anything you need, ask away. I'd be happy to help. That's what I'm here for.

Link to comment

Well, I am trying (not so well) to create a workflow similar to Amazon Suggest using TVRage's API in PHP. Basing off PHP--TVRage (https://github.com/kkirsche/PHP--TVRage) it returns the info that I would want as an array similar to:

TV_Show Object ( [showId] => 25050 [name] => Mike & Molly [showLink] => http://www.tvrage.com/Mike_And_Molly [country] => US [started] => 1284955200 [ended] => [seasons] => 3 [status] => Returning Series [classification] => Scripted [network] => CBS [runtime] => 30 [genres] => Array ( [0] => Comedy [1] => Family ) [airDay] => Monday [airTime] => 21:30 )

 

Not sure how to go about returning the results to Alfred using the information in the array or TV_Show Objects. (I.E. each potential match comes back with an array of that data. Buffy the Vampire Slayer for example returns like ~15 different TV Shows). How would I go about return the array data to Alfred?

Link to comment

Well, I am trying (not so well) to create a workflow similar to Amazon Suggest using TVRage's API in PHP. Basing off PHP--TVRage (https://github.com/kkirsche/PHP--TVRage) it returns the info that I would want as an array similar to:

TV_Show Object ( [showId] => 25050 [name] => Mike & Molly [showLink] => http://www.tvrage.com/Mike_And_Molly [country] => US [started] => 1284955200 [ended] => [seasons] => 3 [status] => Returning Series [classification] => Scripted [network] => CBS [runtime] => 30 [genres] => Array ( [0] => Comedy [1] => Family ) [airDay] => Monday [airTime] => 21:30 )

 

Not sure how to go about returning the results to Alfred using the information in the array or TV_Show Objects. (I.E. each potential match comes back with an array of that data. Buffy the Vampire Slayer for example returns like ~15 different TV Shows). How would I go about return the array data to Alfred?

 

Using PHP... get my workflows class off my blog. http://dferg.us. If you include it in your project (see the amazon suggest because its mine too), you can see exactly how to use it (plus I have usage examples on the blog). You will see how to iterate through the items, use the result() function to create a new feedback result, and then use the toxml() function to send it back to Alfred.

 

If there's anything I can help you with on it, let me know.

Link to comment

So using the workflows class I was able to get the XML generated but for some reason not sure how to get it back into alfred. The XML I generated was (beautified a bit for easier reading):

 

<?xml version="1.0"?>
<items>
	<item uid="2930" arg="http://www.tvrage.com/Buffy_The_Vampire_Slayer" valid="yes" autocomplete="no">
		<title>Buffy the Vampire Slayer</title>
		<subtitle>Buffy the Vampire Slayer is Canceled/Ended. It ran for 7 seasons.</subtitle>
		<icon type="fileicon">/Applications/Alfred.app</icon>
	</item>
	<item uid="31192" arg="http://www.tvrage.com/shows/id-31192" valid="yes" autocomplete="no">
		<title>Buffy the Vampire Slayer - Season Eight: Motion comics</title>
		<subtitle>Buffy the Vampire Slayer - Season Eight: Motion comics is Canceled/Ended. It ran for 1 seasons.</subtitle>
		<icon type="fileicon">/Applications/Alfred.app</icon>
	</item>
	<item uid="21766" arg="http://www.tvrage.com/The_Vampire_Diaries" valid="yes" autocomplete="no">
		<title>The Vampire Diaries</title>
		<subtitle>The Vampire Diaries is Returning Series. It ran for 4 seasons.</subtitle>
		<icon type="fileicon">/Applications/Alfred.app</icon>
	</item>
</items>

Full Unbeautified XML: http://pastebin.com/f33RF8Kg

Full Beautified XML: http://pastebin.com/w2VWiN5s

 

Sadly I don't know how to push that back to Alfred. I wanted to use the 'arg' value to open that URL. I'm passing yes to valid. Not sure how to go about it. I'm running it as a "Script Filter" (not sure if that's what I want to use or not for this). The code to generate the XML is:

 

	require_once('workflows.php');
	require_once('TVRAGE/TVRAGE.class.php');
	require_once('TVRAGE/TV_Show.class.php');
	require_once('TVRAGE/TV_Shows.class.php');
	require_once('TVRAGE/TV_Episode.class.php');
	//create new workflow
	$w = new Workflows();
	// Grab input
	$input = "{query}";

	//Use the input to search TVRage
	$show = TV_Shows::search($input);
	//use foreach loop to set the information for each result
    foreach ($show as $each) {
    	//set the information available to us
     	$thisShow = array(
     		'uid' => $each->showId,
     		'arg' => $each->showLink,
     		'name' => $each->name,
     		'subtitle' => "",
     		'status' => $each->status,
     		'airDay' => $each->airDay,
     		'airTime' => $each->airTime,
     		'network' => $each->network,
     		'seasons' => $each->seasons,
     	);

     	//set the subtitle based on the status of the show. We want the user to get information pertinent to the show.
     	if($thisShow['status'] == "Returning Series") {
     		$thisShow['subtitle'] = $each->name . " is a " . $thisShow['status'] . ". It is aired " . $thisShow['airDay'] . " at " . $thisShow['airTime'] . " on " . $thisShow['network'] . ".";
     	} else if ($thisShow['status'] == "Canceled/Ended") {
     		$thisShow['subtitle'] = $thisShow['name'] . " is " . $thisShow['status'] . ". It ran for " . $thisShow['seasons'] . " seasons on " . $thisShow['network'] . ".";
     	} else if ($thisShow['status'] == "TBD/On The Bubble") {
     		$thisShow['subtitle'] = $thisShow['name'] . " is on the bubble for being renewed. If it is renewed, it airs on " . $thisShow['airDay'] . " at " . $thisShow['airTime'] . " on " . $thisShow['network'] . ".";
     	} else {
     		$thisShow['subtitle'] = $thisShow['name'] . " is aired on " . $thisShow['airDay'] . " at " . $thisShow['airTime'] . " on " . $thisShow['network'] . ".";
     	}

     	$fileIcon = "fileicon:/Applications/Alfred.app";
     	$valid = "yes";

     	//$w->result(uid, arg, title, subtitle, fileicon, valid, autocomplete)
		$w->result($thisShow['uid'], $thisShow['arg'], $thisShow['name'], $thisShow['subtitle'], $fileIcon, $valid, 'no');
     }

     // Return the result xml
     print $w->toxml();

 

 

Not sure how to interact with Alfred or that I'm using the classes in workflows.php correctly (i.e. $w->result). If you want to see the TVRage class I'm using:
https://github.com/kkirsche/PHP--TVRage

 

The Script filter options are set to:

dPvnodC.png

 

EDIT: Updated to more complex code. Same thing happens (i.e. nothing in alfred). Functions correctly (I think) as an independent script though.

 

If it's any help, the workflow itself exported from Alfred:

https://docs.google.com/file/d/0BxYIGe3RKbtKWk5Ib3NzeTRIMmM/edit?usp=sharing

Edited by R4z3r
Link to comment

So using the workflows class I was able to get the XML generated but for some reason not sure how to get it back into alfred. The XML I generated was (beautified a bit for easier reading):

 

<?xml version="1.0"?>
<items>
	<item uid="2930" arg="http://www.tvrage.com/Buffy_The_Vampire_Slayer" valid="yes" autocomplete="no">
		<title>Buffy the Vampire Slayer</title>
		<subtitle>Buffy the Vampire Slayer is Canceled/Ended. It ran for 7 seasons.</subtitle>
		<icon type="fileicon">/Applications/Alfred.app</icon>
	</item>
	<item uid="31192" arg="http://www.tvrage.com/shows/id-31192" valid="yes" autocomplete="no">
		<title>Buffy the Vampire Slayer - Season Eight: Motion comics</title>
		<subtitle>Buffy the Vampire Slayer - Season Eight: Motion comics is Canceled/Ended. It ran for 1 seasons.</subtitle>
		<icon type="fileicon">/Applications/Alfred.app</icon>
	</item>
	<item uid="21766" arg="http://www.tvrage.com/The_Vampire_Diaries" valid="yes" autocomplete="no">
		<title>The Vampire Diaries</title>
		<subtitle>The Vampire Diaries is Returning Series. It ran for 4 seasons.</subtitle>
		<icon type="fileicon">/Applications/Alfred.app</icon>
	</item>
</items>

Full Unbeautified XML: http://pastebin.com/f33RF8Kg

Full Beautified XML: http://pastebin.com/w2VWiN5s

 

Sadly I don't know how to push that back to Alfred. I wanted to use the 'arg' value to open that URL. I'm passing yes to valid. Not sure how to go about it. I'm running it as a "Script Filter" (not sure if that's what I want to use or not for this). The code to generate the XML is:

 

	require_once('workflows.php');
	require_once('TVRAGE/TVRAGE.class.php');
	require_once('TVRAGE/TV_Show.class.php');
	require_once('TVRAGE/TV_Shows.class.php');
	require_once('TVRAGE/TV_Episode.class.php');
	//create new workflow
	$w = new Workflows();
	// Grab input
	$input = "{query}";

	//Use the input to search TVRage
	$show = TV_Shows::search($input);
	//use foreach loop to set the information for each result
    foreach ($show as $each) {
    	//set the information available to us
     	$thisShow = array(
     		'uid' => $each->showId,
     		'arg' => $each->showLink,
     		'name' => $each->name,
     		'subtitle' => "",
     		'status' => $each->status,
     		'airDay' => $each->airDay,
     		'airTime' => $each->airTime,
     		'network' => $each->network,
     		'seasons' => $each->seasons,
     	);

     	//set the subtitle based on the status of the show. We want the user to get information pertinent to the show.
     	if($thisShow['status'] == "Returning Series") {
     		$thisShow['subtitle'] = $each->name . " is a " . $thisShow['status'] . ". It is aired " . $thisShow['airDay'] . " at " . $thisShow['airTime'] . " on " . $thisShow['network'] . ".";
     	} else if ($thisShow['status'] == "Canceled/Ended") {
     		$thisShow['subtitle'] = $thisShow['name'] . " is " . $thisShow['status'] . ". It ran for " . $thisShow['seasons'] . " seasons on " . $thisShow['network'] . ".";
     	} else if ($thisShow['status'] == "TBD/On The Bubble") {
     		$thisShow['subtitle'] = $thisShow['name'] . " is on the bubble for being renewed. If it is renewed, it airs on " . $thisShow['airDay'] . " at " . $thisShow['airTime'] . " on " . $thisShow['network'] . ".";
     	} else {
     		$thisShow['subtitle'] = $thisShow['name'] . " is aired on " . $thisShow['airDay'] . " at " . $thisShow['airTime'] . " on " . $thisShow['network'] . ".";
     	}

     	$fileIcon = "fileicon:/Applications/Alfred.app";
     	$valid = "yes";

     	//$w->result(uid, arg, title, subtitle, fileicon, valid, autocomplete)
		$w->result($thisShow['uid'], $thisShow['arg'], $thisShow['name'], $thisShow['subtitle'], $fileIcon, $valid, 'no');
     }

     // Return the result xml
     print $w->toxml();

 

 

Not sure how to interact with Alfred or that I'm using the classes in workflows.php correctly (i.e. $w->result). If you want to see the TVRage class I'm using:

https://github.com/kkirsche/PHP--TVRage

 

The Script filter options are set to:

dPvnodC.png

 

EDIT: Updated to more complex code. Same thing happens (i.e. nothing in alfred). Functions correctly (I think) as an independent script though.

 

If it's any help, the workflow itself exported from Alfred:

https://docs.google.com/file/d/0BxYIGe3RKbtKWk5Ib3NzeTRIMmM/edit?usp=sharing

 

I don't use the print command at the end to return the XML, i typically use echo. So echo $w->toxml(); I'm not sure if ithat makes any difference at all or not. If the workflows class is generating XML it seems like the script is working. The only thing i'm wondering now is if there is some warning or error in the code that produces additional output that you don't see. When trying to work out things like this, what I typically would do is take all the code, put it in a php file, and run that from the command line. See if there is anything else that shows up other than the XML. If there is.. any kind of script warning or error, something else you echo'd out at one point and forgot to remove, then Alfred isn't going to to show it.

 

Check those few things out and let me know your results. Keep me up to date, I'll help me you get this sorted out.

Link to comment

Print and echo each do the same thing (of nothing for me in this case). 

When running it via terminal, it seems to work correctly as well. There was one error related to strtotime() which was easily remedied. But even after fixing that, I have been unable to get this to work.

u55nX4q.png

 


Everything there seems to be correct which is why it's confusing me so much. Formatted on pastebin: http://pastebin.com/NYtPNEqx
 

Link to comment

Print and echo each do the same thing (of nothing for me in this case). 

When running it via terminal, it seems to work correctly as well. There was one error related to strtotime() which was easily remedied. But even after fixing that, I have been unable to get this to work.

u55nX4q.png

 

Everything there seems to be correct which is why it's confusing me so much. Formatted on pastebin: http://pastebin.com/NYtPNEqx

 

 

I just got it to work. Seems like the Workflows class got cut off on the bottom? I got errors from that originally from that. I fixed that, then I got the errors from not having set the timezone, I did that and it seems to work fine now for me?

Link to comment

Ah, that was it. For whatever reason when I cloned it from github it must have been cut off. I fixed the timezone set issue with date_default_timezone_set() in the script to let users set their timezones. Thanks! Also, how would I use the arg="" value and open that value in the browser? (so if someone presses enter on it, I send the arg value to the default browser to be opened. Thank you again for your help.

Link to comment

Ah, that was it. For whatever reason when I cloned it from github it must have been cut off. I fixed the timezone set issue with date_default_timezone_set() in the script to let users set their timezones. Thanks! Also, how would I use the arg="" value and open that value in the browser? (so if someone presses enter on it, I send the arg value to the default browser to be opened. Thank you again for your help.

 

When using $w->result() the second parameter is the arg value. Check my blog (http://dferg.us) for updated versions of the Workflows class and documentation. Anyway, thats the value that is set to arg. Anything set there will be passed to the next item in the workflow. So, in your case, after the script filter, attach a Open URL action, and set the url of it to {query}. That will grab the value passed to it from the previous step.

Link to comment

Got it. Was just the last part that I needed. Thanks! I'll have that up soon. Still a number of features to add but I think you've gotten me to the point where it's just a matter of putting everything together and adding all that I want to add to it. Thanks for your help!

Link to comment

Got it. Was just the last part that I needed. Thanks! I'll have that up soon. Still a number of features to add but I think you've gotten me to the point where it's just a matter of putting everything together and adding all that I want to add to it. Thanks for your help!

 

Yes sir. Anytime. Hit me up if you have any other questions. I'd be happy to help out. Thats what I'm here for :)

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