Jump to content

Python script and Alfred variables


Recommended Posts

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.

image.thumb.png.dd1cc34f2af4705dccc7834711fb97d0.png

 

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

 

image.thumb.png.98e577b58cb3dbb4af93f6c8c240338f.png

 

The variable assignments

pathvariable.thumb.png.a4a61665ff824ac7e9fb12d22669201c.pngfilenamevariable.thumb.png.40cb342ccc0b39eac378137fce27f4ad.png

 

 

the debug results I get

image.thumb.png.bcad812315ffcceb2f541182787a9c8e.png

 

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

 

Stephen

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

image.thumb.png.cef78252656252a7c19c69bfef6975b1.png

 

With the split Arg utility configured as

image.png.334e514f0fab5dbbecb218cf96c2daeb.png

 

However, it still doesn't work

image.thumb.png.fe52df36a092a794217746d9a2da74b9.png

 

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

 

Johnny

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