Jump to content

Easy Selection of Folders with Same Name Based on Path

Recommended Posts

I do a lot of WordPress development and so have a lot of folders called 'wp-content' in my Sites folder.


I have file filter that searches only within Sites, then I type "wp-co" and all the wp-content folders are listed. I can see their paths under their names and scroll to the one I want.


Not bad, but I'd like something even better.


What I'm really after is a file filter that when I type 'wp-cxc' will show me all the wp-content folders with "xc" (such as "Sites/xchange/wp-content/ ) in the path name.
Or 'wp-cap' for all wp-content folders that have "ap" in the path.


The problem I'm having is that Alfred doesn't search in the path name, so if I activate my filter and type, for example 'wp-cxchange' Alfred won't return the "wp-content" folder in the parent directory that contains 'xchange'.


So is there a way to do this with the basic Workflow building blocks or will I need a script?



Link to comment

I think the only way you could use Alfred's built-in components would be if you used tags or Spotlight comments to add the project name to each 'wp-content' folder.


You could try this workflow, which filters across directory levels, so you'd set up a Fuzzy Folder for ~/Sites and then "sites xch wp" (assuming "sites" is the keyword you assigned to ~/Sites) will match ~/Sites/xchange/wp-content/.


The best way would probably be to write a Script Filter, however.


This is a very rudimentary prototype, but if you use this as a Script Filter (Language = zsh, Escaping = Double Quotes, Backquotes, Dollars, Backslashes), it will do more or less what you want (filter on the project name, open the wp-content folder):

#!/usr/bin/env zsh

export LC_CTYPE=UTF-8

function projname() {
  echo "$( echo "$1" | awk -F/ '{print $(NF-1)}' )"

function contains() {
  local string="${1:l}"
  local substring="${2:l}"
  if test "${string#*$substring}" != "$string"
    return 0    # $substring is in $string
    return 1    # $substring is not in $string

wpdirs=(${(f)"$(mdfind -onlyin ~/Sites '(kMDItemContentType == public.folder) && (kMDItemFSName == wp-content)')"})

if [[ -z "$query" ]]; then
  for p in $wpdirs; do
    pname="$( projname "$p" )"
    if contains "$pname" "$query"; then

echo '<?xml version="1.0" encoding="utf-8"?>'
echo '<items>'

for proj in $projects; do
  pname="$( projname "${proj}" )"
  cat <<EOF
<item valid="yes" type="file">
  <icon type="fileicon">${proj}</icon>

echo '</items>'
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...