I'm trying to make a program consisting of an AppleScript interfacing with bash files (so that I get the fancy Cocoa GUI). I assume this is a simple task, because one of the file types in the new file-menu (cmd+n) is shell scripts (.sh).
I've done a few half-assed tries to get it working (do shell script "sh file.sh"), but I can't figure out how to run those files.
Are there any gurus out there who can help me? :3
If anything is unclear, feel free to ask questions.
If you just want to launch shell scripts from the Cocoa gui, you don't need the AppleScriptObjC bridge, make a Cocoa program in Objective-C and use the NSTask class: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/Reference/Reference.html.
Related
Let's say I'm making my own programming language, and it has its own scripting file extension.
Then the user, let's say, drags their script file of whatever program they made onto the .exe of the programming language
How, programmatically, could the programming language figure out how to use the fact that they "opened the script" by dragging it on the .exe, as a means to run the script?
I'm brand new to Cocoa programming and was wondering how to run a .command file through my program. I've seen use of NSTask but being new I don't quite understand all of the lines and can't seem to get it to work. I don't need to monitor the terminal results or retrieve the data that terminal puts out, I just need to run it.
The most simple way is:
system("/path/to/my/script.command");
This is not Cocoa, this is Posix.
I'm about to start a new Cocoa project from scratch and one of the requirements I have already been given is being able to choose either a Cocoa GUI or a command line mode from the same executable. Scriptability may be a possible addition in the future but that is not a concern right now.
What is the best strategy for going about this in Cocoa, especially if I want to maintain certain Cocoa features like Obj-C garbage collection?
Xcode will generate a main.m for you with a main function that has the command line arguments. You should parse them and if you need to stay in command-line mode, never do the application startup. If you are being a GUI, just start normally.
I'm dying to know how I can make a GUI for ffmpeg and jhead in OSX. I've been looking for a solution for a while and thought you, stackoverflow's users, could help me. Maybe you know some document I haven't come across of or, better, a tutorial to make a GUI.
I love those two tools but I like the simplicity of drag/drop operations.
Note: I don't need a GUI for them, I want to make one.
There is a tutorial for wrapping command-line tools using NSTask, on the Cocoa Dev Central site:
Wrapping UNIX Commands
Wrapping UNIX Commands Part II
It's a few years old now, but should get you started.
If you are asking "How do I create a GUI application in Mac OS X that interfaces to a command line tool" the answer is NSTask. Although, if the command line tool provides a programming API, using that would be preferable to invoking the command line tool itself.
If you are asking "How do I create a GUI application in Mac OS X" the answer is to read a book about it and look at the Apple tutorial docs. Cocoa Programming on Mac OS X by Aaron Hillegass was my starting point.
You can use a scripting language like Tcl, Python or Ruby with a toolkit like Tk which uses native widgets on the mac.
First create a Modal Dialog NIB with the needed GUI.
When called in C , create an NSReleasePool, and then the magic sauce.
[NSApplication sharedApplication]
ProcessSerialNumber psn;
GetCurrentProcess( &psn );
TransformProcessType(&psn,kProcessTransformToForegroundApplication);
SetFrontProcess( &psn );
Later after you load the NIB from the Bundle, issue
[NSApp runModalForWindow:[controller window]];
[[controller window] close];
Without the TransfromProcessType(), the Terminal app will get keystrokes, not the Modal Dialog.
This may not be the best answer but in the book "Xcode unleashed" is a chapter how to embed a Command Line Tool inside a Cocoa Application. Maybe you should have a look. Nice book anyway.
On your Leopard/Snow Leopard disk you can find XCode, but you can also download it from the Apple Developer Community. XCode comes with the Interface Builder, which lets you build GUI's and you can rig to your commands using the Cocoa framework.
You are too late, there is already a GUI frontend for ffmpeg called ffmpegX, but anyway, you would create a model that either wraps or uses the library or executable.... if it uses the executable you can use popen to invoke the executable, write to its STDIN, and read from its STDOUT. The view and controller would be basically the same as you would design it for any other GUI application. Since this is a Cocoa post, you could use Objective-C and Cocoa to the make the GUI, but it really can be implemented in any language.
what's a good way to scripting or creating programs unders windows?
How about python?
You will need Notepad, and to learn JScript (not Javascript... JScript), VBScript or Batch. Then you can easily create small scripts, somewhat equivalent to bash shell scripts on Linux.
For the first two, you can read the Windows Script Host documentation.
Windows Powershell is becoming the new Windows scripting language. Being a full .NET language, it is inevitably much more powerful that the horrible old batch scripts one used to have to write (and still retains much of the syntactic sugar of scripting/shell languages).
You can do VBScript without the need to install anything.
Open notepad and enter the following text:
MsgBox "Hello"
Save it as filename.vbs
Double click the file you just created, congratulations - you just created and ran a VBScript.
I'd like to plug AutoIt. It's a free download and comes with it's own editor that can be quickly/easily installed anywhere. The language is very rich and comes with a large library of user defined functions. Integrated context-sensitive help with syntax display. There's even a GUI editor. A final plus is that it compiles to .exe so will run on any win2k/xp/vista/2k3/2k8/7 PC.
I always use Python for scripting on Windows.
A vague question usually gets a vague response.
Download a compiler or interpreter and find a tutorial.
With more information we can better point you in the right direction
I would say there are three clever choices here:
Scripting: Use JSCRIPT because much of what you learn about JSCRIPT can be used in Javascript. You can either graduate to Javascript/AJAX in the browser, or Microsoft .HTA apps.
Or, you could use Python because it has standard modules to do just about anything a sysadmin would do plus addons to access Windows .COM objects and WMI. You can then either graduate to Python on a UNIX platform, Jython (which is Python in the JVM) or IronPython which opens up the entire world of .NET for you.
And there is of course, the non-scripting choice which is about creating programs under Windows. If you choose this you probably have an end-game in mind that is beyond scripting, so start with SharpDevelop and IronPython. Then, as you gain confidence, start working with C# still using the same Sharpdevelop toolset. With this choice you can also graduate to UNIX applications using the MONO .NET environment although if you want to do GUI apps on UNIX you will need to use GTK# instead of Windows Forms.