Jump to content

Issue getting Alfred to display XML as results


Recommended Posts

I've been working on a brief workflow that grabs a list of FTP favorites from Transmit and serves them up as Alfred results. Ideally, actioning any one of these results would mount the specified server as a external drive. So far though, I've been unable to get Alfred to load the generated XML as results. Below, I've provided some details that might be useful to pin-point the issue:

 

The workflow is PHP-based, though it also relies on a bit of Applescript to fetch the list of favorites from Transmit. (Much of the code & concepts come courtesy @jdfwarrior!) I thought the issue might be related to the Applescript – returning invalid XML, or maybe nothing at all. I tried writing the generated XML to a file (instead of echoing it back to Alfred, as per the code below.) The output seemed valid but I am still unable to get Alfred to load the XML into its results list! It just gets stuck on the pre-defined loading text.

 

I hope this all makes sense. Any and all help is much appreciated!

 

PHP:

/* FOLLOWING CODE IS ENTERED DIRECTLY INTO ALFRED'S "SCRIPT FILTER"
** EDITOR AND ISN'T WRAPPED IN <?PHP?> TAGS. THE FILTER REQUIRES A
** SPACE-SEPARATED ARGUMENT, THE INTERPRETER IS SET TO PHP, AND I
** LIMITED THE 'ESCAPE {QUERY}' OPTION TO DOUBLE QUOTES AND DOLLARS.
*/
require_once('extension_utils.php');
$utils = new ExtensionUtils();
$results = array();
$query = stripcslashes("{query}");
$favesGet = exec('osascript transmit_actions.scpt');
$favesObj = explode(', ',$favesGet);
$i = 0;
foreach( $favesObj as $fave ):
	$i++;
	$item = array(
		'uid' => 'fave-'.$i,
		'arg' => $fave,
		'title' => $fave,
		'subtitle' => 'Mount '.$fave.' as volume...',
		'icon' => 'icon.png',
		'valid' => 'yes'
	);
	array_push( $results, $item );
endforeach;

if ( count( $results ) > 0 ):
	echo $xml;
endif;

/* IN ORDER TO TEST/DEBUG THE XML OUTPUT
** I REPLACED THIS FINAL IF-STATEMENT WITH
** THE FOLLOWING CODE:
*/
// $xml = $utils->arrayToXml($results);
// $path = "output.txt";
// $file = fopen($path, 'w') or die("can't open file");
// fwrite($file,$xml);
// fclose($file);

 

Applescript:

-- FILE NAME: transmit_actions.scpt
--
-- APPLESCRIPT THAT RETURNS A LIST OF THE
-- NAMES OF FTP FAVORITES FROM TRANSMIT:
---------------------------------------------
set names to {}
tell application "Transmit"
	repeat with fave in favorites
		set faveName to name of fave
		set names to names & faveName
	end repeat
end tell
tell application "Transmit" to quit
return names

 

XML Output: (Abbreviated and formatted...)

<?xml version="1.0"?>
<items>
	<item uid="fave-1" arg="Christian et Christine">
		<title>Christian et Christine</title>
		<subtitle>Mount Christian et Christine as volume...</subtitle>
		<icon>icon.png</icon>
		<valid>yes</valid>
	</item>
	<item uid="fave-2" arg="Clifford Wright">
		<title>Clifford Wright</title>
		<subtitle>Mount Clifford Wright as volume...</subtitle>
		<icon>icon.png</icon>
		<valid>yes</valid>
	</item>

 

 

Link to comment

Just a heads up, bigluck has already made a workflow that returns Transmit faves.

 

Also, ExtensionUtils has been a constantly evolving and updated thing. It's not called just Workflows. I have a newer version available on my blog, dferg.us. Documentation and a more updated version can be found there.

 

I also need to push a few more updates, but I have to get a few more things done in preparation for Alfred 2.

Link to comment

</items> seems to be missing at end

 

My 2 cents

 

Keen eye, but as I'd mentioned, I've abridged the XML output for the sake of brevity (I have quite a few favorites) so the closing </items> tag actually is generated correctly by the Applescript. Thanks nonetheless!

 

Just a heads up, bigluck has already made a workflow that returns Transmit faves.

 

Also, ExtensionUtils has been a constantly evolving and updated thing. It's not called just Workflows. I have a newer version available on my blog, dferg.us. Documentation and a more updated version can be found there.

 

I also need to push a few more updates, but I have to get a few more things done in preparation for Alfred 2.

 

Hey David! Thanks for pointing me towards bigluck's workflow. This was really more of a learning exercise for me as I don't do much coding beyond the limited PHP/JS confines of web development and design. But I took a quick look at the updated "Workflows" functions and they look great. Anyways, I'm sure you've heard it before but once again: thanks for all the work you've put in to Alfred!

Link to comment

Keen eye, but as I'd mentioned, I've abridged the XML output for the sake of brevity (I have quite a few favorites) so the closing </items> tag actually is generated correctly by the Applescript. Thanks nonetheless!

 

 

Hey David! Thanks for pointing me towards bigluck's workflow. This was really more of a learning exercise for me as I don't do much coding beyond the limited PHP/JS confines of web development and design. But I took a quick look at the updated "Workflows" functions and they look great. Anyways, I'm sure you've heard it before but once again: thanks for all the work you've put in to Alfred!

 

Glad to help. If you need any help getting started with the workflows class or just creating workflows in general, don't hesitate to ask. I'm always willing and available to help out.

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