Jump to content
jdfwarrior

Generating Feedback in Workflows

Recommended Posts

Probably because you have superfluous whitespace in your <title> tag. It starts with a newline, then a bunch of spaces, before the title you actually wanted. You should rewrite it as <title>Incubus</title>.

 

It's still a valid XML document. And I think Alfred should just strip the string so it can be displayed correctly.

 

The `minidom` library in Python behaves differently in 2.6 and 2.7. These extra new line will be added if use the `toprettyxml` function of minidom in Python2.6.

Share this post


Link to post

It's still a valid XML document. And I think Alfred should just strip the string so it can be displayed correctly.

 

The `minidom` library in Python behaves differently in 2.6 and 2.7. These extra new line will be added if use the `toprettyxml` function of minidom in Python2.6.

It may be valid, but it doesn't mean the same thing. You shouldn't be emitting "pretty" XML when sending it to another tool anyway; "pretty" XML is intended for human consumption.

Share this post


Link to post

Quick question: the <item arg=“"> should be removed completely in order to use <arg></arg>? Or Alfred will use <arg></arg> if set and ignore the other (no need to remove the other for good)?

 

 

I am confused. Starting with...

<item uid="rdioartist" arg="r96664" valid="yes" autocomplete="Incubus">

 

Which is the recommended format to exclude uid ?

<item uid="" arg="r96664" valid="yes" autocomplete="Incubus">

<item arg="r96664" valid="yes" autocomplete="Incubus">

 

When would you use <arg></arg> ?

Share this post


Link to post

When would you use <arg></arg> ?

 

As I understand it: if you want your arg to contain multiple lines, you need to use the <arg></arg> format; XML attributes (e.g. arg="") cannot contain newlines

 

Cheers :)

Share this post


Link to post

Is there any chance that JSON feedback will be supported? It's far nicer to work with in most languages (such as Python) and should produce cleaner Workflows.

Share this post


Link to post

Is there any chance that JSON feedback will be supported? It's far nicer to work with in most languages (such as Python) and should produce cleaner Workflows.

Agree.  Please support JSON.  Much easier to handle JSON responses from APIs.

Share this post


Link to post

What is the "type" attribute used for? is it optional? if it is this should be pointed out in the post =) (I'm assuming that it is optional)

When I set the value to "file": what is the advantage for Alfred/Alfred's user?

The Format

(...)

type

The type attribute allows you to specify what type of result you are generating. Currently, the only value available for this attribute is file. This will allow you to specify that the feedback item is a file and allows you to use Result Actions on the feedback item.

(...)

Share this post


Link to post

What is the "type" attribute used for? is it optional? if it is this should be pointed out in the post =) (I'm assuming that it is optional)

When I set the value to "file": what is the advantage for Alfred/Alfred's user?

 

Yes, the 'type' attribute is optional. Right now, it is used only to specify if a result is a file/folder or not.

 

If your script filter is returning files as its results (like David Ferguson's Faves workflow), setting the type to 'file' will allow the user to interact with the result just like a file search result. They can add it to the buffer, Quicklook, activate the actions panel, etc.

Share this post


Link to post

Why does UID ordering not work in hotkey-activated scripts? Is there any way to simulate this?

 

Could you provide a little more explanation as to what you are doing/looking for? If your script filter generates UIDs for the items, as long as the UID is unique, they should be shown in the order in which the output was produced by the script. If the UID isn't unique and has been selected in the past, then Alfred will prioritize that result based on his knowledge.

Share this post


Link to post

Yes, the 'type' attribute is optional. Right now, it is used only to specify if a result is a file/folder or not.

 

If your script filter is returning files as its results (like David Ferguson's Faves workflow), setting the type to 'file' will allow the user to interact with the result just like a file search result. They can add it to the buffer, Quicklook, activate the actions panel, etc.

 

Just an FYI. I was tinkering with this and had some issues. For others trying to use this functionality, it is important to note that the argument passed with the item whose type is file must be the full path to that item. That is, in order for a Script Filter to return results that the user can right-arrow into to access Alfred's file browser, both the "type" and "arg" keys are necessary, tho neither is sufficient. And the "type" key must have "file" as its value, and the "arg" key must have the full file path as its value. 

 

Hope that helps someone else.

Share this post


Link to post

Could you provide a little more explanation as to what you are doing/looking for? If your script filter generates UIDs for the items, as long as the UID is unique, they should be shown in the order in which the output was produced by the script. If the UID isn't unique and has been selected in the past, then Alfred will prioritize that result based on his knowledge.

 

A hotkey triggered script I have generates UIDs for a specific input string (so when I type 'c' it generates a list of sortable elements with static UIDs). If I trigger the script via the script keyword, it sorts correctly ('myscript c' sorts), but if I use a hotkey to activate my script filter, it does not work.

Share this post


Link to post

A hotkey triggered script I have generates UIDs for a specific input string (so when I type 'c' it generates a list of sortable elements with static UIDs). If I trigger the script via the script keyword, it sorts correctly ('myscript c' sorts), but if I use a hotkey to activate my script filter, it does not work.

 

I've confirmed this. I'll submit a bug report as soon as possible I've submitted a bug report, as I don't believe this is the appropriate behavior.

Edited by Tyler Eich

Share this post


Link to post

Hey guys, 

 

so i'm mostly off the Alfred community now and that's why I have to ask a question here (this forum has become huge). Is it now possible to make a dynamic list of results? 

 

For single results I'm assuming that it is easy to "update" it regularly now that there are external triggers (even tho it's still hacky). But what about lists? You don't want to refresh if the user has started scrolling down, thus taking him back to result #1. 

 

Any news? 

Share this post


Link to post

No. Basically, Alfred is stateless. So the results exist only in one form.

 

To get a better idea of how Alfred works, make a workflow that has a keyword and runs this script:

<?php

$counter = 20;
while ( $count > 0 ) :
  sleep (1);
  $counter -= 1;
endwhile;

echo "I took 20 seconds to execute.";
?>

Then, run that workflow and quickly switch to a terminal and run "ps aux|grep php"

 

You should see something like

php -r '$counter = 20; while ( $count > 0 ) : sleep (1);$counter -= 1;endwhile;echo "I took 20 seconds to execute.";'

in the processes.

 

What this tells you is that Alfred just grabs that code and runs it through the PHP interpreter, receives the STDOUT, parses the XML, and displays it accordingly. So, if this were invoked by a script filter (ignore that it would fail because it doesn't produce valid XML). The code would be run for each key press, and the results would be refreshed as if it were executed for the first time because, for all intents and purposes, it is being run the first time.

 

So, no dice.

Share this post


Link to post

Any news on icon url implementation? My plugin is unusable without this function :(

 

Unfortunately no that feature isn't available at this time. One way that several users have gotten around this is to use their script to download the icons first and cache them. Not sure if that is a viable option for your workflow or not.

Share this post


Link to post

As for David, here are a few bits of code. If you're using PHP, then you can modify this:

<?php

$bundle = 'mybundleid';

$data  = $_SERVER['HOME'] . "/Library/Application Support/Alfred 2/Workflow Data/$bundle";
$cache = $_SERVER['HOME'] . "/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/$bundle";

if ( checkConnection() ) {
	// We have an internet connection, so we can try to download icons
	$icons = getTheIcons();

	// Depending on how many icons you'd need here, you might consider grabbing just a few on each
	// workflow run so that the user doesn't need to wait forever to download all of them. Instead,
	// let them populate over time.
	foreach ( $icons as $key => $icon ) {
		if ( file_exists( "$cache/icons/$icon" ) ) {
			$icons[ $key ] = "$cache/icons/$icon";
		}
	    else {
	    	file_put_contents( "$cache/icons/$icon", file_get_contents( "$urlToIcon/$icon" ) );
	    }
	    unset( $icon );
	}
} else {
	$icon = "$data/icons/default.png";
}

// Do some logic here that will allow you to place whichever icon you need or fallback to the
// default icon.

function getTheIcons() {
	// do something to get the icons here.
}

function checkConnection() { 
	ini_set( 'default_socket_timeout', 1);

	// First test
	exec( "ping -c 1 -t 1 www.google.com", $pingResponse, $pingError);
	if ( $pingError == 14 )
		return FALSE;

	// Second Test
    $connection = @fsockopen("www.google.com", 80, $errno, $errstr, 1);

    if ( $connection ) { 
        $status = TRUE;  
        fclose( $connection );
    } else {
        $status = FALSE;
    }
    return $status; 
}

If you want to create a bash script that will download things in the background, then use the following with the command execute the following with "bash downloadIcon.sh 'iconName' 2>&1 /dev/null &" You could also put all the necessary ones in a file and have the script read them from a file. Or you could call this from another script.

#!/bin/bash

# downloadIcon.sh

# Script to download the necessary icons in the background

# Make sure that something is set here.
[[ -z $0 ]] && echo "Provide at least one option to run this script." && exit 1

# Check for an Internet connection
ping -t 1 -c 1 www.google.com 2>&1>/dev/null
[[ $? -ne 0 ]] && exit 1

bundle = 'mybundleid';
cache="$HOME/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/$bundle";

baseLink="http://www.urltoicons.com"
curl -sL "$baselink/$0" "$cache/icons/$0"

Edited by Shawn Rice

Share this post


Link to post

Is it still true that the only "type" available is "file"? I really wish there was a reference document for these kinds of question...

Share this post


Link to post

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
×