Terminal OSX app open with arguments.

Will be denied, you are not allowed to control the Terminal from AppleScript, neither Finder or System Events. Anything that can be used to control the system.[quote=242316:@Michel Bujardet]@Marco Hof True, but now you mention it… for Shell I use NSTask (because supposedly Apps will be rejected when using the Xojo Shell). [/quote]
NSTask is required for executing “helper” applications, applications that are Sandboxed and within the main application.

Indeed. Problem is, some people have taken that as “Xojo shell is not permitted in the MAS”, which is not true.

Also, I am not entirely sure the requirement for NSTask is as mandatory as you say. I have an app in the MAS using Valdemar de Sousa’s startup helper, which uses the Xojo shell to launch the app.

Since Terminal cannot get scripting entitlements, back to square one.

Here is the shell feeding a script to Terminal, based on Marco’s post :

[code] s = new shell

dim f as FolderItem = SpecialFolder.UserHome.child(“Downloads”).child(“script.sh”)

s.execute("chmod +x "+f.ShellPath)

s.execute("open -b com.apple.terminal "+f.ShellPath)[/code]

I placed the script in Downloads, it can be anywhere of course, including inside the app bundle Resources folder.

[quote=242749:@Marco Hof] sh.Execute("osascript -e 'tell application ""Terminal""' -e Activate -e 'do script ""winexe -u user%pass 192.168.2.42 cmd""' -e 'end tell'") [/quote]

Thanks Marco. Now it works perfect.
I paste my code result with variables. Perfectly with WINEXE. I hope it help to someone that need it.


Dim sh As New Shell

sh.Execute("osascript -e 'tell application ""Terminal""' -e Activate -e 'do script ""winexe -U " + User + "%" + Pass + " //" + IPSelected + " cmd""' -e 'end tell'")

Thanks.

Now that that’s solved, why doesn’t this work when called directly from the Shell? What error are you getting?

He wants to see the terminal. The shell does not show it as default.

The original post makes it sound as if the only reason for launching Terminal is because winexe doesn’t work directly in Shell. But if you’re right, he can ignore my question.

I need use terminal because WINEXE command don’t work in interactive shell. Winexe connect to a remote PC like ssh (WINEXE = PSEXEC for OS X), and you can execute remote commands in Terminal. But when I run WINEXE in shell and connect nothing is showed when I execute a simple command like ‘dir’… I only get it work in terminal.app

If shell runs winexe well I’ll use it.

And no error is returned by the Shell?

No, just no results is showed. I can use interactive shell for other commands (ls, cp, rm, cd etc…), but winexe don’t works. I tried it a lot of times.

I’m sorry if it sounds like I’m repeating myself, but want to make certain. After execution, the Shell.ErrorCode property is set to 0?

Yes. Like it works, but don’t show the results.

Well now I’m going to have figure out how to install winexe so I can try this. :slight_smile:

'Install winexe in osx
In terminal:

[code] ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)” < /dev/null 2> /dev/null

brew install winexe[/code]

Thanks.

I really didn’t want to install homebrew so I want to see if there is another way first.

What about writing a .command file (which is usually a /bin/bash script) and then opening it?

Well, I finally broke down and used homebrew to install winexe, albeit into a directory other than /usr/local where it wanted to change permissions and ownership. So that part worked.

Unfortunately, my Windows 10 VM won’t allow a proper connection and the error is beyond my Google skills. Oh well.

In a Xojo-built macOS Desktop.app, I also want to launch an external (Xojo-built) console application, and see it’s output in the Terminal window.
I don’t want to use AppleScripts, as it just adds unnecessary complications in macOS 10.15 (Entitlements for AppleScript needed - which seems like an overkill for such a simple Task).

So what are the options?

  • write a .sh “on the fly” (containing /path/to/consoleapp arg1 arg2), then s.execute("open -b com.apple.terminal "+ temporaryscript.ShellPath)
  • write a .command “on the fly”, and then temporarycommandfile.Launch()
  • is there another way that does NOT involve writing a dynamic script, save it, launch it? Is there really no way without AppleScript or creating/writing a dynamic Script?

I’ve tried to use the command open, but can’t get it to both open Terminal.app and start executing a ConsoleApp along with parameters…
I’ve also tried to just point a Xojo FolderItem to the ConsoleApp, and use FolderItem.Launch(). Funny thing here is: Without parameters, that works just fine. With parameters, nothing seems to happen at all…

Why not NSWorkspace launchApplicationAt ?
https://developer.apple.com/documentation/appkit/nsworkspace/1534810-launchapplication?changes=latest_minor

How would you set that up?

If I point it to Terminal.app, then Terminal launches just fine. Also multiple instances using NSWorkspaceLaunchNewInstance work just fine and as expected.

However, NSWorkspaceLaunchConfigurationArguments will then obviously go to Terminal.app. And handing over /bin/echo test just does nothing in the opened Terminal.app.

And if I point it to launch /bin/echo with argument test, then it obviously doesn’t open Teminal.app - and I don’t (yet?) see a way in NSWorkspace to say “launch /bin/echo WITH argument test IN Terminal.app”.