Jump to content

Python script and Alfred variables

Recommended Posts



I am building a workflow in Alfred to copy a file with a Power Point template to a directory and name it based on a file I have selected through a universal action.
The idea I am employing can be seen in the following figure.



I am trying to perform the operations with a Python script, but for reasons I don't quite understand, sometimes the value of the file name is None and at other times the directory name is None. It's as if both variables cannot be read at the same time.


The python script code is


import sys
import os
import shutil


fileName = str(os.getenv("fileName"))
path = str(os.getenv("path"))


baseFilePath = "/Users/johnny.alvarado/Documents/CUB - MS DS/Template.pptx"
destinationFilePath = path + "/" + fileName + ".pptx"


#shutil.copy(baseFilePath, destinationFilePath)




configured as




The variable assignments




the debug results I get



Could someone guide me on how to solve this problem?


Environment information:

- Mac OS Sonoma 14.0

- Alfred 5.1.13


Thank you,



Edited by jalvarado
To add the environment information
Link to comment

I must say the way I'd do it (ignoring for a moment the Python as it's years since I used it) would be to have a single stream from your universal action, Get Path Basename, save that as a variable, Get Path Dirname, save that as a variable and then use Arg & Vars to feed both variables to a Split Arg utility in turn to feed them to your Python script.


You may also like to check this Alfred help page Reading Environment Variables (if you've not already checked it) on passing variables to (among others) Python.



Link to comment
3 hours ago, Stephen_C said:

I must say the way I'd do it (…) would be to have a single stream from your universal action


You are absolutely correct. The issue is precisely that there are two streams instead of one, so two different things are activating the Python script, each missing half of the information.

Link to comment

Hi Stephen and Vitor,


Thank you for helping me.


My interpretation of your suggestion is the following



With the split Arg utility configured as



However, it still doesn't work



It seems to me that my remaining problem is how to share the original input to the second automation task.



Link to comment

To give you a general idea of how to configure things in a single stream take a look at this workflow in the Alfred gallery: New Folder. (Full disclosure: it's one of my own workflows. However, it's carefully annotated to show how the various variables are saved and then, where necessary, combined.)



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