Jump to content

Script can't open a file that exists if I use the tilde (~) to refer to my home directory in a workflow variable

Recommended Posts

Hello everyone,

I'm new to Alfred and I love it!

I have a small php script that is in my home folder `~/dev/tag-buddy` and I want to call it from an Alfred workflow.


Simple Script Filter configuration that works fine

I've setup a script filter in bash language with this instruction `/usr/local/bin/php ~/dev/tag-buddy/src/search-tags.php "{query}"` and it works fine.

Below you can see the configuration





Trying to use a variable to handle the path to php script


If I setup a worfklow variable to handle the php script path, like this:





and then I modify the Script Filter Object like this:




I get this error:



So the variable substition has worked fine, since Alfred tries to open the file with the right path, but it doesn't work.


However, if in the workflow variable I write the complete path, replacing the ~ with my actual home directory path, the workflow is fine.


So it doesn't like when using the ~ in a workflow variable.

Am I doing something wrong?







Link to comment

Hi @magobaol, welcome to the forum.


39 minutes ago, magobaol said:

Am I doing something wrong?


Yes. Expanding ~ to your home directory is something that bash (and zsh) does only when it’s directly specified as an argument. If you have a variable with ~ in it, you just have a tilde character.


Putting tagbuddypath=~/dev/tag-buddy in your script will work because bash will expand the tilde before setting the variable, but Alfred doesn’t expand tildes in your workflow variables.


If you want to be able to specify paths with ~/ in Alfred’s settings, you’ll have to manually expand the tildes in your script. Same goes for other variables (i.e. you can’t use $HOME/Documents in Alfred’s workflow variables table, either).


Edited by deanishe
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...