fwdalpha Posted July 2, 2022 Share Posted July 2, 2022 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 Posted July 3, 2022 Share Posted July 3, 2022 You’re using "type": "fileicon". You need to remove that. As per the documentation: Quote By omitting the "type", Alfred will load the file path itself, for example a png. fwdalpha 1 Link to comment
fwdalpha Posted July 5, 2022 Author Share Posted July 5, 2022 Is there a better way to give a second dropdown menu based on the actioned element than to chain script filters together? Seems very repetitive to have to keep chaining them together for nested selections. Link to comment
fwdalpha Posted July 7, 2022 Author Share Posted July 7, 2022 (edited) 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 July 7, 2022 by fwdalpha Link to comment
vitor Posted July 7, 2022 Share Posted July 7, 2022 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. fwdalpha 1 Link to comment
fwdalpha Posted July 7, 2022 Author Share Posted July 7, 2022 Yes! thanks for clarifying that, I do not know shell very well, but I will try to implement this in python. I was able to find a 100% working alternative with external triggers, but your method is definitely more correct. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now