jalvarado Posted October 22, 2023 Posted October 22, 2023 (edited) Hello, 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) sys.stdout.write(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, Johnny Edited October 22, 2023 by jalvarado To add the environment information
Stephen_C Posted October 22, 2023 Posted October 22, 2023 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. Stephen
vitor Posted October 22, 2023 Posted October 22, 2023 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.
jalvarado Posted October 23, 2023 Author Posted October 23, 2023 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. Johnny
vitor Posted October 23, 2023 Posted October 23, 2023 No, you’re still splitting streams. You need everything in one continuous line.
Stephen_C Posted October 23, 2023 Posted October 23, 2023 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.) Stephen jalvarado 1
vitor Posted October 23, 2023 Posted October 23, 2023 Also, in Alfred Preferences → Workflows you can press the + on the bottom left and do Getting Started → Stream Order to see a workflow which teaches more about this. Finally, see the Getting Started Guide for an interactive tutorial on making a workflow. jalvarado 1
jalvarado Posted October 23, 2023 Author Posted October 23, 2023 Thank you Stephen and Vitor. I got it. It is working now! Have a great day!
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