Automator: Change to selected directory and run shell script I'm trying to create a context menu command via Automator service. The context menu command will run a shell script to create some default documents in the given directory. 

I wrote out the shell script which executes correctly when run from the target directory:

#!/bin/bash


touch History.markdown
touch Notes.markdown
touch Plan.markdown

touch ProjectName.tmproj

cat &lt;&lt;TEXT &gt; ProjectName.tmproj
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;currentDocument&lt;/key&gt;
    &lt;string&gt;Notes.markdown&lt;/string&gt;
    &lt;key&gt;documents&lt;/key&gt;
    &lt;array&gt;
        &lt;dict&gt;
            &lt;key&gt;filename&lt;/key&gt;
            &lt;string&gt;Notes.markdown&lt;/string&gt;
            &lt;key&gt;selected&lt;/key&gt;
            &lt;true/&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
            &lt;key&gt;filename&lt;/key&gt;
            &lt;string&gt;History.markdown&lt;/string&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
            &lt;key&gt;filename&lt;/key&gt;
            &lt;string&gt;Plan.markdown&lt;/string&gt;
        &lt;/dict&gt;
    &lt;/array&gt;
    &lt;key&gt;openDocuments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;History.markdown&lt;/string&gt;
        &lt;string&gt;Notes.markdown&lt;/string&gt;
        &lt;string&gt;Plan.markdown&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;fileHierarchyDrawerWidth&lt;/key&gt;
    &lt;integer&gt;200&lt;/integer&gt;
    &lt;key&gt;metaData&lt;/key&gt;
    &lt;dict/&gt;
    &lt;key&gt;showFileHierarchyDrawer&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;windowFrame&lt;/key&gt;
    &lt;string&gt;{{113, 95}, {1230, 900}}&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;
TEXT


I then opened Automator and created a new service. I set the service to receive selected input of folders in Finder.

I then added the following to the top of my shell script to received the selected directory as standard input:

FolderPath=$1
$(cd $FolderPath)


The variable FolderPath definitely gets the current directory. I added a say $FolderPath to the shell script and it says out the entire path when run from the context menu command. 

The problem is that when I try to change to the directory in the variable, nothing happens. I put another say command that spoke the command pwd after the directory change and it says that I'm at my user's root. 

Is there something that automator does differently when dealing with shell scripts?

Here's a screen shot of the entire service.
 

I should also mention that I have tried to just concatenate the folder path and the file name that I've tried to create with the touch command and when I do so it only uses the string name of the file to create:

say "$FilePath/History.markdown" # only says "History dot markdown"


Any help would be greatly appreciated!
The problem here is you have the input being passed to stdin. I don't know why that's the default, but you should be able to just change the popup menu in the top right to "as arguments." I did that and added cd "$1" to the top of the script and it worked.