Jump to content

Show image in Script Filter results


Recommended Posts

import sys
import json
import os 

arg= sys.argv[1]
PATH = '*************'

def create_json_to_send(title, uid, autocomplete, arg, subtitle, path,type_of_icon='fileicon'):
		one_item = {"title":title, "uid":uid, "autocomplete":autocomplete, "arg":arg, "subtitle":subtitle, "icon": {"type":type_of_icon, "path":path}}
		my_json = {"items": [one_item]}
		final = json.dumps(my_json, indent=2)
		return final
	

def send_res_back(arg):
	path = PATH
	list_of_files = os.listdir(PATH)
	for each in list_of_files:
		listed = each.split('.')
		to_match_name = listed[0]
		if to_match_name == arg:
			return path + '/' + each

	return 'NO Match yet'

if __name__ == '__main__':
	path = send_res_back(arg)
	returned_json = create_json_to_send('copy', 'copy', 'copy', 'copy', 'copy image to board', path)
	sys.stdout.write(returned_json)

 

I am currently learning script filters. I understand the power behind it, and am currently trying to make a workflow that takes in an argument that the python script searches a certain directory of images for the name. If it finds the name, it returns the entire path to the file, which I could then use to copy the image to clipboard, or any other action with the full path. One of the things I would like to also do is, that once the image is found, and its according path, the icon shows up as the image itself (which you can see in my code above as the path argument). I've spent a while trying to get this to work, and feel like I am not understanding something fundamental about how script filters work (which is why this is not working). When calling the script, Alfred shows a match in the log, but then nothing else. 

 

 

 

 

 

Link to comment
  • vitor changed the title to Show image in Script Filter results

Thanks. That definitely works and I have tried this, but I found in my personal testing that it's difficult to get used to pressing a character to select an option than hitting return like I am used to on Alfred. My goal is to programmatically be able to read that the return key was selected and then immediately return a new json object on that condition. I found this Toggl workflow that has something like this. Setting an external trigger on the input and output with conditionals seems to work for this.

Edited by fwdalpha
Link to comment
8 hours ago, fwdalpha said:

My goal is to programmatically be able to read that the return key was selected and then immediately return a new json object on that condition.


Which is what the linked code does, through a combination of "valid":false and autocomplete. The code comments explain how it works.

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