How to run shell script in automator with space in users name

I have a shell script that runs from Automator. It works fine on a computer with a user name without any spaces. However I need to run it on a computer that has the user name "staff computer" and I get an error that there is no such directory. Is there a way around this?

Posted on Jan 20, 2023 12:20 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 21, 2023 7:37 AM


JB001 wrote:
There was a space in the folder name so the other techniques came in handy also.


Just expand the quotes to include the Folder Name:

/usr/bin/python3 "$HOME/The Folder Name"/PythonFile.py "$1" "$2"


or this if the script name has spaces

/usr/bin/python3 "$HOME/The Folder Name/Python File.py" "$1" "$2"


even this would work:

/usr/bin/python3 "$HOME"/"The Folder Name"/"Python File.py" "$1" "$2"


See: https://www.gnu.org/software/bash/manual/html_node/Quoting.html

10 replies
Question marked as Top-ranking reply

Jan 21, 2023 7:37 AM in response to JB001


JB001 wrote:
There was a space in the folder name so the other techniques came in handy also.


Just expand the quotes to include the Folder Name:

/usr/bin/python3 "$HOME/The Folder Name"/PythonFile.py "$1" "$2"


or this if the script name has spaces

/usr/bin/python3 "$HOME/The Folder Name/Python File.py" "$1" "$2"


even this would work:

/usr/bin/python3 "$HOME"/"The Folder Name"/"Python File.py" "$1" "$2"


See: https://www.gnu.org/software/bash/manual/html_node/Quoting.html

Jan 20, 2023 1:19 PM in response to JB001

The solution may differ depending on whether this is a one-off or not.


If you're hard-coding the path (not generally recommended, but usable in a pinch), you can quote the path:


/user/bin/python3 '/Users/Staff Computer/Desktop/PythonFile.py'


If this is dynamic (e.g. find the current user's home directory), then some degree of shell substitution via the $HOME variable, which should be safe (maybe coupled with quoting, too).

Jan 21, 2023 7:11 AM in response to Tony T1

I didn't know how to use the environment variable - now I do. This makes it easier to install on a couple computers and works perfectly.


Also I was getting bad info on the user name. I was given the "long name" which had a space. Apple has two user names, a short name that did not include the space and a long name that did. The path uses the short name so there wasn't a space in the name. There was a space in the folder name so the other techniques came in handy also. Details will get you every time.

Thanks Tony

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.

How to run shell script in automator with space in users name

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