I am using zsh with oh-my-zsh in iTerm on macOS. There are some aliases defined in my .zshrc I use often, like this:

 cd ~/Path/To/My/Project;
 build ...;
 rsync ...;

To execute this, I have to switch over to iTerm and run the alias. Now I'd like to be able to do that from anywhere via a hotkey.

I've read that automator is the tool of choice.

I created an action "run shell script" and chose `/bin/zsh/' from the list of available shells.

But running my alias returns zsh:1: command not found.

Am I on the wrong shell? But echo $0 in iTerm gives me -zsh.

How can I run my alias without being in the iTerm window? Any approach will do, Automator is just how I'm trying to accomplish it.

  • 1
    Well, that is a function. Normally, you would write the function in a separate file and place it in a directory defined by fpath. In your .zshrc you would autoload the function in order to use it. – fd0 May 26 '17 at 15:40
  • Oh! And then it would be available in all shells & automator, I guess. Would you say coderwall.com/p/ktv3hq/zsh-autoloading-functions-i which came up after following your hint would be correct? – Urs May 26 '17 at 15:54
  • What do you get from echo $SHELL? – William T Froggard May 26 '17 at 16:25
  • echo $SHELL returns /bin/zsh – Urs May 27 '17 at 8:54

The solution is to source the file dependencies you need inside the automator script.

Example if you added all of your scripts to ~/.zshrc

source ~/.zshrc

You can debug things easier by doing which deploy to check to see if that script is accessible.


Automator runs in its own environment and does not read your shell rc files. The PATH is limited to /usr/bin:/bin:/usr/sbin:/sbin. None of the environment is exported for further use. You could define the function in Run Shell Script and run it like this:

 deploy () {
 cd ~/Path/To/My/Project;
 build ...;
 rsync ...;


Though this is somewhat limited.

  • That sounds reasonable. But I have several functions, e.g. for build and rsync. Can they be "nested" in Run Shell Script? – Urs May 27 '17 at 8:56
  • @Urs Function definitions must precede their first call. Assuming that you are doing so in your script, I see no issues. – fd0 May 27 '17 at 12:48

I found a workaround without automator;

On https://apple.stackexchange.com/a/136931/60854 I read about hotkeys in iTerm. I made a hotkey in Keys > Hotkey to call iTerm to the foreground and another one in Profile > Keys > Key Mappings to enter a string deploy\n. Now I press cmd-i cmd-o and here we go.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .