Jump to content

Open templates, based on argument


Recommended Posts

Hello,

 

I apologize if this is obvious, but I've spent a lot of time, looking for an answer.

 

What I want: When writin `ai` in Alfred, I want Adobe Illustrator. I have a list of templates, that I want to be able to select, using an argument. E.g.: `ai 1920` should open `~/templates/1920.ait`, `ai 1080` should open `~/templates/1080.ait` and so on.

 

How I've tried to do it: Python3 was my first port of call. But I can't find any documentation for python3 and Alfred 5. Everything seems to be from earlier versions.

 

I then tried a list filter. But it keeps searching, instead of accepting my argument.

 

Can anybody point me in the right direction, both on using python, and on prioritizing workflows over search?

 

Screenshot 2024-08-18 at 00.31.58.png

Screenshot 2024-08-18 at 00.33.01.png

Screenshot 2024-08-18 at 00.35.59.png

Link to comment
  • 3 weeks later...
On 8/18/2024 at 4:20 AM, vitor said:

You can use Python with any object that takes a script, like a Run Script Action.


But you don’t need code at all. Connect a Keyword Input with default settings to an Open File Action set to open ~/templates/{query}.ait and you’re done.

 

Thank you. That does work, and I can open the file with the script, but then I loose the list of choices. Is there a way to keep them?

 

 

 

My script, if anybody needs something similar:

import sys
import os

query = "{query}".lower()
app = "/Applications/Adobe Illustrator 2024/Adobe Illustrator.app"

lookup = {"1080":"RM_1080.ait",
  "1920":"RM_1920.ait",
  "A3":"RM_A3.ait",
  "A4":"RM_A4.ait",
  "A5":"RM_A5.ait",
  "A6":"RM_A6.ait",
  "A7":"RM_A7.ait",
  "so":"RM_SoMe.ai",
  "portrait":"RM_Thumbnail_Portrait.ait",
  "wallpaper":"RM_Wallpaper.ai",
  "icon":"RM_icon.ait"}

if query.strip() == "" or query not in lookup:
  os.system(f"open '{app}'")
  
else:
  os.system(f"open -a '{app}' '/Users/RM/Illustrator-templates/{lookup[query]}'")

 

Untitled-1.png

Edited by RasmusMalver
Forgot the screenshot
Link to comment
38 minutes ago, vitor said:

Always prefer with input as argv over with input as {query}.


As for the choices, keep the List Filter. But A4 is a Title, and RM_A4.ait is an argument on that same item. The logic is the same.

 

Yes, but I'm lazy! I can easily make a python dictionary with aliases and filenames, but it takes minutes to use the Alfred UI to add all the options.

 

Of course I can export, unzip, edit, zip and import, but is there no easier way to add many things to a list filter?

 

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