Jump to content

Error when executing Terminal Shell Script from AppleScript


This topic is 1585 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Background:
I am moving files that are created and exported to another system. I create the files in FM and then manually enter the Terminal and execute a command. Now I want to automate this process. I'm on macOS 10.13 with FM 17.

Problem:
When I perform the Terminal command via AppleScript I get an error. I can do the exact same command manually in the Terminal, and it works, but not when Apple Script tries to do it.

Details:
Relevant script steps from Filemaker:

Set variable [$shellScript; "tell application \"Terminal\" ¶do shell script \"./sendtonav CSSE " & $shellScriptParameter & "\"¶end tell"]
Perform AppleScript [$shellScript]

This results in the variable $shellScript to be populated with, for example: 

tell application "Terminal"
do shell script "./sendtonav CSSE 20191216 0008400987"
end tell

(The Shell Script "sendtonav" looks for a file named "CSSE 20191216 0008400987" in a folder located in the Desktop folder on the Mac, and exports it to another system.)

 

If I perform this in Filemaker, or in AppleScripts script editor, I get the following error: "Terminal got an error: sh: ./sendtonav: No such file or directory" number 127 ( I also get this error if I write the wrong numbers in the sendtonav script, ie the file doesn't exist).

However; If I copy the text ./sendtonav CSSE 20191216 0008400987 and paste it in the Terminal, it works!

 

I am stuck. I really don't understand why AppleScript can't execute this command, while it all works perfect if I do it manually in the Terminal...!?

 

Please help. 😩

Link to comment
Share on other sites

If you get the same error in the Script Editor application, then the problem is not Filemaker related. 

AFAIK, the correct Applescript command to use with the Terminal application is 'do script', not 'do shell script' (as I tried to tell you in your previous question).

 

  • Thanks 1
Link to comment
Share on other sites

Aha, I thought it was the other way around (ie you should use "shell" script). 🤦‍♂️

I tried it out, and it worked when I got rid of the "shell". Thank you very much!! 🙏

These scripts are originally more than 15 years old, and it may be that the Shell thing was a necessity from the past...

Thanks again!

Actually, when looking at Apples Developer pages, they refere to "Do shell script": https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/CallCommandLineUtilities.html

 

Is there a difference between the built in Terminal commands and the scripts?

Link to comment
Share on other sites

This topic is 1585 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.