Interacting with a bash shell script (on Mac OS)

I have a shell script (that was given to me, I didn’t write it nor do I speak “bash”).
I’ve been tasked to put a graphical front end onto it.

Once the script is run it asks the user for various inputs (first an integer representing the number of files that will follow, then the paths to those files, then a string that will be used to search in each of the files.).

How should I best go about doing this?
I’ve instantiated a shell and can get the script running (using Shell.Execute) but I’m never getting the opportunity to enter the subsequent data the script should be asking for. I’ve tried all of the modes but not getting the results I’m expecting.

I’d appreciate any advice.
Thanks!
Phil

Please post your code?

Mike,

Sorry – I do realize it helps to show examples of what isn’t working but I didn’t really have anything that looked coherent to post… just a bunch of testing bits as I tried to get things to work.

I kept digging and I believe I figured out what the issue was.
I’m using a shell in interactive mode and because of the way the script’s output was formatted on multiple lines (and with blanks lines) I wasn’t seeing what I was expecting where I was expecting it.

Right now I’m interacting with the script by checking for script prompts in the DataAvailable event handler and supplying script inputs via the shell.WriteLine method.

I spoke too quickly.

Although I am able to interact with the script in Interactive mode:

  1. I can get it started, using Shell.Excecute, passing the script’s Folderitem.ShellPath
  2. Receive output from the script (in the DataAvailable method)
  3. Send the script input (strings, integers and a path to a folder)

When the script takes the information and performs its operation on the files I get “read only file system” errors reported from the script. When I run the script directly from a bash terminal – with the same file paths and variables – it runs as expected.

I’ve included the code in the DataAvailable event (it’s not very clean). Please let me know what other information would be relevant.
Thanks,
Phil

[code]Sub DataAvailable()
var theResult As string
var theCommand As string
var dump As string
var endOfResult As String
var indexOfXMP As Integer

// theReadString = theShell.ReadAll

theResult = theShell.Result
endOfResult = theResult.right(40)

if endOfResult.IndexOf(“Permission Denied”) <> -1 then
dump = theShell.ReadAll

var msg As string
msg = "You need to change the permissions on the selected script."
msg = msg + " Open a terminal window and type: chmod +x " + TheScriptPath + ", then restart the application."
MessageBox(msg)

end if

if endOfResult.IndexOf(“How many XMPs do you have?”) <> -1 then
dump = theShell.ReadAll
theShell.WriteLine(str(NumberOfXMPs))
end if

if endOfResult.IndexOf(“Please enter XMP #”) <> -1 then
dump = theShell.ReadAll

indexOfXMP = endOfResult.NthField("#", 2).Val - 1
theShell.WriteLine(XMP_PathsArray(indexOfXMP))

end if

if endOfResult.IndexOf(“string to search for with XMP #”) <> -1 then
dump = theShell.ReadAll

indexOfXMP = endOfResult.NthField("#", 2).Val - 1
theShell.WriteLine(UniqueStringsArray(indexOfXMP))

end if

if endOfResult.IndexOf(“Where is your project folder?”) <> -1 then
dump = theShell.ReadAll
theProjectFolderPath = theProjectFolderPath + "/ "
theShell.WriteLine(theProjectFolderPath)
end if

if endOfResult.IndexOf(“Proceed? (y/n)”) <> -1 then
dump = theShell.ReadAll

end if

End Sub[/code]

Shell is not Terminal and does not have the same permissions. Security and permissions on newer macOS systems can be complicated and confusing. @Sam Rowlands might be able to help, but a lot will depend on exactly what the bash script is doing.

Tim,

Thanks for the reply.
“Shell is not Terminal” – that would seem to explain a lot.
I’m glad to go over what the script does with whoever thinks they might be able to offer some advice.

I will reach out to @Sam Rowlands to see if he is willing to offer any insights.

Thanks,
Phil

It does! Wrapping command line with Xojo can have really cool results, but it can also be really tricky to develop.

One of the biggest things to look for would be literal paths to protected areas of the file system. If you see sudo at all anywhere in the script, you’ll need AuthroizeMBS to get an elevated shell.

Sam is pretty smart when it comes to macOS security issues. Be sure to pick up his AppWrapper when you’re ready to distribute!

@Tim Parnell,

No sudo commands in the script. It just uses exiftool commands to apply/check some metadata from one or more XMP files against a folder of files. I wouldn’t have thought that would raise security issues. I thought perhaps it had something to do with how I was interacting with the script/shell.

I seem to be able to interact with the script just fine. When the script tries to touch the files I get “Read-only file system” reported from the script… also “exiftool: command not found” errors.

These ones are going to be the “Shell is not Terminal” issue. If you use the full path to the executable, that usually resolves that one.

This is where I’m thinking you have a permissions issue. I’m not sure what to explore, you usually don’t get permissions issues in debug.