Automator: use folder pathname with spaces

How can I use a folder whose pathname contains one or more spaces in Automator?


I have the following workflow. It works on folder's whose names do not include spaces, but fails (though without an error message) when I run it with a folder whose name does include a space.


iMac Line (2012 and Later)

Posted on Nov 9, 2019 3:22 AM

Reply
Question marked as Top-ranking reply

Posted on Nov 9, 2019 4:21 AM

If you are just dragging and dropping the space punctuated folder name containing the AppleWorks documents, then you do not need the first get and set actions — based on what you have shown here. Just make this change:


cd "$1"


Consider using --headless instead of --invisible. That --headless also eliminates the need for --nologo too.


This also works (tested with 30 *.cwk in a space punctuated folder:


#!/bin/bash

shopt -s nullglob
for file in "$1"/*.cwk
do
    /Applications/LibreOffice.app/Contents/MacOS/soffice --headless \
    --convert-to pdf --outdir "$1" "$file"
done
shopt -u nullglob
exit 0


The zsh shell does not break on file or folder white space, so no quotes would be needed with it.

Similar questions

7 replies
Question marked as Top-ranking reply

Nov 9, 2019 4:21 AM in response to davidneale1

If you are just dragging and dropping the space punctuated folder name containing the AppleWorks documents, then you do not need the first get and set actions — based on what you have shown here. Just make this change:


cd "$1"


Consider using --headless instead of --invisible. That --headless also eliminates the need for --nologo too.


This also works (tested with 30 *.cwk in a space punctuated folder:


#!/bin/bash

shopt -s nullglob
for file in "$1"/*.cwk
do
    /Applications/LibreOffice.app/Contents/MacOS/soffice --headless \
    --convert-to pdf --outdir "$1" "$file"
done
shopt -u nullglob
exit 0


The zsh shell does not break on file or folder white space, so no quotes would be needed with it.

Nov 9, 2019 11:12 AM in response to davidneale1

Sure. Look in the Automator Files & Folder Library, and drag/drop the Ask for Finder Items action into your workflow before your Run Shell Script action.


The prompt can be anything you want. Start at: Desktop, and Type: Folders. I would not select Allow Multiple Selection unless you have a for loop construct in your Bash code to process multiple folders.


for file in "$@"
do
   ...
done
exit


The "$@" is the list of items being passed to the Run Shell Script action, even if it is one item. It will be in POSIX (UNIX) path format.


Review the Automator content here. Take into consideration that some things may have changed from the time this was authored until current implementations of Automator. The bigger picture at this site is here.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator: use folder pathname with spaces

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.