Eric
Eric

Reputation: 1261

Running a shell script through AppleScript

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.

Upvotes: 1

Views: 5586

Answers (2)

eWhizz
eWhizz

Reputation: 1

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

Upvotes: 0

adayzdone
adayzdone

Reputation: 11238

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

Upvotes: 2

Related Questions