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

 

1128035268_Screenshot2021-08-01at18_15_40.png.3d86adf4f6c286db442fe05052feebea.png

 

 

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:

474556114_Screenshot2021-08-01at18_15_52.png.d280a1b8bb07229a989db6ed70665097.png

 

 

 

and then I modify the Script Filter Object like this:

1323366065_Screenshot2021-08-01at18_15_06.png.ee9ffa75de08ab8a47b40ea92fac27a6.png

 

 

I get this error:

alfred-tb-4.thumb.png.9355d1997090162a8fd0da3b3b4b93ce.png

 

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?

 

Thanks,

Francesco

 

 

 

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