1

This is my first time trying to create a terminal script and then using AppleScript to run the code. I've tested my terminal script line by line in the terminal (it works...), but would like to put it in a file that can be called by applescript. So far, I've created a file called "/Applications/MAMP/htdocs/global_admin/import_database_command_line.sh" where I've saved all of the individual commands, the first being:

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot;

I then use AppleScript to call the script as:

do shell script
"/Applications/MAMP/htdocs/global_admin/import_database_command_line.sh"

Unfortunately, for each line in my script I get an error, such as:

error "/Applications/MAMP/htdocs/global_admin/import_database_command_line.sh:
line 1: : command not found

Any help in coordinating my AppleScript and the file that contains my shell commands would be appreciated.

2 Answers 2

2

You need to include #!/bin/sh in the top line of your .sh file

#!/bin/sh

echo "Hello, world!"

You then need to make the script executable:

chmod +x import_database_command_line.sh
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the quick response! Now I'm getting the error: sh: /Applications/MAMP/htdocs/global_admin/import_database_command_line.sh: /bin/sh^M: bad interpreter: No such file or directory
0

This is because the 'do shell script' AppleScript command is expecting to run the shell commands contained within the quotes. It is not expecting to be calling another script as you are doing. Just put your commands within the quotes, separated by semi-colons.

do shell script "/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot; #other_command; #etc"

Link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.