Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Error when executing Terminal Shell Script from AppleScript

Featured Replies

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. 😩

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).

 

  • Author

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?

I think that 'do shell script` tries to run the script in the (invisible) "shell". To run a script inside the terminal window, you need to tell the Terminal application to `do script`. But I am mostly surmising here.

 

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.