Jump to content
rafegoldberg

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>

 

 

Share this post


Link to post

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.

Share this post


Link to post

</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!

Share this post


Link to post

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.

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