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>