0

I have created an Automator application that will create a new folder for a Project with subfolders with the help of a Shell Script. The application starts by asking for a Project Name and a Location (directory) and once it is created it opens the newly created project folder.

eg:

enter image description here

Up to that point it works as intended, however I am also trying to add some files to the subfolders automatically but I'm stuck and I haven't been able to find the solution on my own.

Basically I am trying to copy the files from another folder into one of the newly created subfolders but I'm getting (mostly) the following two errors:

  1. The action “Run Shell Script” encountered an error: “usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory” usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
  2. The action “Run Shell Script” encountered an error: “cp: /path/to/sourcefile/file.pdf: No such file or directory”

    This is what I have:

enter image description here

mkdir "$1/$2"
mkdir "$1/$2/Guides_and_Bulletins"
mkdir "$1/$2/Pictures"
mkdir "$1/$2/Schematics"
mkdir "$1/$2/Schematics/Calculator"
mkdir "$1/$2/Schematics/As_built"
mkdir "$1/$2/Site_Docs"

cp "/path/to/sourcefile/file.pdf" "/$1/$2/Guides_and_Bulletins/file.pdf"

In that example I am trying to copy the file.pdf from one location to the newly created Guides_and_Bulletins subfolder from the actions above but of course it is not working.

Any help will be greatly appreciated! Thank you

Note: I of course am changing the path for cp "/path/to/sourcefile/file.pdf" "$1/$2/Guides_and_Bulletins/" to the correct one

  • "All kinds of errors" is not a helpful piece of information. I suspect you're getting multiple instances of one specific error, but you have not told us what that error is. Please edit your question to include the specific text of the error or errors you are encountering. – Jim L. Nov 6 at 20:57
  • Yes. Sorry about the oversight. The two errors I get the most are the following: The action “Run Shell Script” encountered an error: “usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory” usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory – ShellScriptNoob Nov 6 at 21:36
  • And also this one: The action “Run Shell Script” encountered an error: “cp: /path/to/sourcefile/file.pdf: No such file or directory” – ShellScriptNoob Nov 6 at 21:53
  • Please edit your question to include the errors. – Jim L. Nov 6 at 21:57
  • @JimL. Done. Thank you – ShellScriptNoob Nov 6 at 22:11
0

You created a directory:

mkdir "$1/$2"

But then you try to copy a file to a potentially different directory:

cp "/path/to/sourcefile/file.pdf" "/$1/$2/Guides_and_Bulletins/file.pdf"

Try:

cp "/path/to/sourcefile/file.pdf" "$1/$2/Guides_and_Bulletins/file.pdf"

Also, some simplification of your script is possible:

mkdir -p "$1/$2/Guides_and_Bulletins" \
         "$1/$2/Pictures" \
         "$1/$2/Schematics" \
         "$1/$2/Schematics/Calculator" \
         "$1/$2/Schematics/As_built" \
         "$1/$2/Site_Docs"

cp "/path/to/sourcefile/file.pdf" "$1/$2/Guides_and_Bulletins/"
  • Thank you for your reply. I tried your suggestion but I get: The action “Run Shell Script” encountered an error: “cp: /path/to/sourcefile/file.pdf: No such file or directory”. Also, I used your simplification suggestion as well but now the name of the folder is just mkdir $1 (I have it setup so that I can copy the project name from my schedule and the application gets the name automatically from the clipboard). EDIT: of course I'm changing the '/path/to/sourcefile/file.pdf' to the actual path name but it doesn't work – ShellScriptNoob Nov 6 at 21:43
  • I am trying to make it work within Automator – ShellScriptNoob Nov 6 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.