Terminal OSX app open with arguments.

Can I open OSX terminal app but with arguments??

Example:

Shell.execute(“Open /Aplications/Utilities/terminal.app ‘winexe -u user%pass 192.168.2.42 cmd’”)

I don’t want to execute in shell, I need open terminal app. Winexe command don’t work in shell.

I can only get open terminal, but arguments don’t works.

Thanks

  • What error (if any) are you getting?
  • Are you sure that the SHELL is putting you in the correct path to even find “winexe”

And I am going to assume for the sake of argument that WINEXE.APP is actually installed
and that you made a TYPO when you entered /APPLICATIONS above

I do not think the terminal takes arguments.

What you can do instead is to point an f folderItem to winexe, and do

f.Launch(" -u user%pass 192.168.2.42 cmd")

If winexe is a Unix executable, the terminal will be launched.

Or something like:
osascript -e ‘tell application “Terminal” to do script “winexe -u user%pass 192.168.2.42 cmd”’

[quote=242283:@Marco Hof]Or something like:
osascript -e ‘tell application “Terminal” to do script “winexe -u user%pass 192.168.2.42 cmd”’[/quote]

If the app is to go into the MAS, it will be necessary to get a target entitlement to script Terminal.

[quote=242313:@Marco Hof]True, but now you mention it… for Shell I use NSTask (because supposedly Apps will be rejected when using the Xojo Shell).
But what about things like ShowURL and FolderItem.Launch? Do you know if those are those MAS friendly?

edit: I’m asking because I’m trying to stay as x-plat as possible and try to avoid using declares (and plug-ins) unless there’s really no other way.[/quote]

I have a couple apps in the MAS that rely on the Xojo shell , updated one recently and everything is just fine. At one point, there are urban legends about using the shell worth debunking. Pretty much the same for AppleScript. As long as you get the entitlement to script an app, you’re fine. The only things taboo are System Events and Desktop.

I also use ShowURL in every one of my apps, and FolderItem launch in a couple of them.

Sorry for deleting my question just before you replied. I wanted to make a new topic because I didn’t want to go off-topic.

But no longer needed. You’ve answered it all. Thanks Michel. As always, highly appreciated. :slight_smile:

You’re welcome, Marco.

[quote=242258:@Michel Bujardet]I do not think the terminal takes arguments.

What you can do instead is to point an f folderItem to winexe, and do

f.Launch(" -u user%pass //192.168.2.42 cmd")

If winexe is a Unix executable, the terminal will be launched.[/quote]

I’ve tried:

dim f as folderitem = Getfolderitem("/usr/local/bin/winexe", FolderItem.PathTypeShell) f.Launch(" -u user%pass //192.168.2.42 cmd")

But when press de button it does nothing.

If I put this code, the terminal launch:

dim f as folderitem = Getfolderitem("/usr/local/bin/winexe", FolderItem.PathTypeShell) f.Launch("")

The arguments don’t work.

Thanks

Forgive me for asking, but have you verified in the terminal that the arguments work as expected ?

Yes, in fact, now the program work opening the terminal and I copy to the clipboard the complete sequence, then I paste it on terminal:

winexe -U 5%4a //192.168.2.123 cmd

Work perfectly. But I’m trying do it directly from de program, when I press a Button terminal open with complete sequence.

Thanks

You are right, there is definitely a bug in launch on Mac OS X. Whatever argument prevents it to work.

Thanks for all Michel.

Can you think of any solution occurs ?

[quote=242341:@Antonio Psb]Thanks for all Michel.

Can you think of any solution occurs ?[/quote]

I tried to launch a bash script but it was open as a text file, although all execution permissions are set and it works in Terminal.

The best I can think of is to use the same code as the interactive terminal example to provide, if not the ability to enter commands.

I believe, though, Marco’s Applescript solution is the best. It provides both the real terminal and scripting.

[quote=242376:@Michel Bujardet]I tried to launch a bash script but it was open as a text file, although all execution permissions are set and it works in Terminal.

The best I can think of is to use the same code as the interactive terminal example to provide, if not the ability to enter commands.

I believe, though, Marco’s Applescript solution is the best. It provides both the real terminal and scripting.[/quote]

The interactive terminal example is the first thing I tried, but, winexe don’t work on it.
Sorry, but I don’t know how to use Marco’s Applescript.

Thanks

Like this:

  Dim sh As New Shell
  sh.Execute("osascript -e 'tell application ""Terminal"" to do script ""winexe -u user%pass 192.168.2.42 cmd""'")

You can also write a little shell script. That’s a bit more of a hassle but probably easier if you need to do a whole lot of scripting and you prefer that above Applescript. I think Terminal only takes a shell script as argument. So if you write a little script like this:

#!/bin/bash
winexe -u user%pass 192.168.2.42 cmd

…and do: chmod +x script.sh

then you should be able to call is with:
open -b com.apple.terminal /path/script.sh

But in your case, I would use the call to osascript.

[quote=242602:@Marco Hof]Like this:

  Dim sh As New Shell
  sh.Execute("osascript -e 'tell application ""Terminal"" to do script ""winexe -u user%pass 192.168.2.42 cmd""'")

You can also write a little shell script. That’s a bit more of a hassle but probably easier if you need to do a whole lot of scripting and you prefer that above Applescript. I think Terminal only takes a shell script as argument. So if you write a little script like this:

#!/bin/bash
winexe -u user%pass 192.168.2.42 cmd

…and do: chmod +x script.sh

then you should be able to call is with:
open -b com.apple.terminal /path/script.sh

But in your case, I would use the call to osascript.[/quote]

Ok, work perfectly. Thanks.
But the terminal open in background. Is there any chance that Terminal open in front ?

Thanks you.

Use “do shell script” instead of “tell application Terminal to do script”.

[quote=242252:@Antonio Psb]
Winexe command don’t work in shell.[/quote]

I think if you use the full path, it will work in a shell

open Terminal
type
which winexe

That should you show the path.

sh.Execute("osascript -e 'tell application ""Terminal""' -e Activate -e 'do script ""winexe -u user%pass 192.168.2.42 cmd""' -e 'end tell'")