1. Copy workflow NewFile and rename copy to NewDir
2. Change keywords nf to nd and nfo to ndo in NewDir
3. Change variable open_file to open_dirs in the two Args and vars utilities.
4. Edit the Run script action, change the with input as argv to with input as {query}, and running instances should be Sequentially, and then replace the Script with below:
# -----------------------------------------------------------------------------
# CREDITS:
# - Step 1 and partially Step 3 is based on Vítor Galvão:s NewFile workflow
# NOTES:
# - This is just a simple wrapper around the built-in macOS bash-shell and mkdir command.
# - To use spaces in directory names, use quotes (single and double work): "Dir 1", 'Dir 1', "Dir 1-"{1..3}, 'Dir 2-'{1..3} etc.
# - This uses spaces as argument delimiters, change Step 2 below if you want to use another delimiter
# USE EXAMPLES:
# - nd dir1
# - nd dir1 dir2
# - nd 'dir 1'
# - nd "dir 1"
# - nd 'dir 1' 'dir 2'
# - nd 'dir '{1..10}
# - nd "dir "{1..10}
# - nd 'dir 1-'{1..10} 'dir 2-'{1..10}
# - nd "dir 1-"{1..10} "dir 2-"{1..10}
# - nd 'dir 1' 'dir 2' 'dir 3' 'dir {4,5,10}' 'dir '{10..100}
# - nd 'dir 1' 'dir 2' 'dir 3-'{1..3} 'dir 4-'{1..3}
# - nd dir{1..10}/subdir{1..10}
# - nd 'dir '{1..10}/'subdir '{1..10}
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Step 1. Set pwd/dir_path to that of frontmost app
dir_path="$(osascript -l JavaScript -e '
const frontmost_app_name = Application("System Events").applicationProcesses.where({ frontmost: true }).name()[0]
if (frontmost_app_name === "Finder") {
decodeURIComponent(Application("Finder").insertionLocation().url()).slice(7).slice(0, -1)
} else if(frontmost_app_name === "Path Finder") {
decodeURIComponent(Application("Path Finder").finderWindows[0].target.url()).slice(7).slice(0, -1)
} else {
decodeURIComponent(Application("Finder").desktop.url()).slice(7).slice(0, -1)
}
')"
# -----------------------------------------------------------------------------
# Step 2. Set spaces as delimiters for arguments
IFS=$' '
# -----------------------------------------------------------------------------
# Step 3. for each arg, create dir(s), and if ndo command: open them afterwards
for dir in {query}; do
# set new dir loc according to frontmost app
new_dir_loc="${dir_path}/${dir}"
# create new dir(s) according to arguments
mkdir -p "${new_dir_loc}"
# if using ndo command, then open newly created dir(s) afterwards
if [[ "${open_dirs}" == 'yes' ]];
then open "${new_dir_loc}";
fi
done
# -----------------------------------------------------------------------------
The above works for simple Alfred commands such as:
nd dir to create dir named dir in foremost dir.
nd dir{1,2,3} to create dirs named dir1,dir2,dir3 in foremost dir.
nd dir{1..3} to create dirs named dir1,dir2,dir3 in foremost dir.
nd dir{1..3} dir{5..8} to create dirs named dir1,dir2,dir3,dir5,dir6,dir7,dir8 in foremost dir.
nd dir{1..3}/dir{1..3} to create dirs dir1, dir2, dir3, dir1/dir1, dir1/dir2, dir1/dir3, dir2/dir1, dir2/dir2 etc. starting from foremost dir.
etc.