Jump to content

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.

Link to comment

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.

Link to comment
  • 1 month later...

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

Link to comment
  • 3 months later...
  • 1 month later...
  • 2 months later...

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.

(...)
Link to comment

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.

Link to comment
  • 2 weeks later...

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.

Link to comment

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.

Link to comment

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.

Link to comment

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
Link to comment
  • 3 months later...

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? 

Link to comment
  • 2 weeks later...

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.

Link to comment
  • 2 weeks later...

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.

Link to comment

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
Link to comment
  • 3 months later...
  • 3 weeks later...
  • vitor unpinned this topic

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