Re: Integrating Unix scripting in Cocoa app
Re: Integrating Unix scripting in Cocoa app
- Subject: Re: Integrating Unix scripting in Cocoa app
- From: Ron Fleckner <email@hidden>
- Date: Wed, 8 Aug 2007 00:02:29 +1000
On 07/08/2007, at 10:45 PM, Sherm Pendley wrote:
On Aug 7, 2007, at 8:25 AM, Ron Fleckner wrote:
On 07/08/2007, at 9:52 PM, Sherm Pendley wrote:
On Aug 7, 2007, at 6:38 AM, Ron Fleckner wrote:
My app has a Scripts menu from which the user can run Ruby,
Python, Perl and AppleScripts. I want to be able to support
shell and other script types and to do so, I need to get the
shebang line from the script file and pass that to NSTask.
You don't need to know anything about the shebang line to execute
a script with NSTask. Just launch the script directly as an
executable, and the kernel will read the shebang line to
determine out what interpreter to use.
But if the script is NOT an executable?
In that case, you shouldn't be trying to execute it to begin with.
The #! line exists for the kernel's use, not so that you can
attempt to subvert the file permissions the user has chosen.
The context is a Scripts menu in an application. If the user wishes
to add a script to that menu by adding the script to a folder in the
app's Application Support folder, then I think there is no subversion
going on. As a bonus, the user can add a plain text file without the
need to make it an executable and the app will run the script. Will
this break anything? Will the kernel suffer? I appreciate your
help, but I don't understand your concerns.
I just want users to be able to add a Unix script of any kind as a
plain text file or an exe and run it. For both cases, this works:
NSString *path = [menuItem representedObject];
NSArray *components = [[NSString stringWithContentsOfFile:path]
componentsSeparatedByString:@"\n"];
NSString *task = [[components objectAtIndex:0] substringFromIndex:
2];
[NSTask launchedTaskWithLaunchPath:task arguments:[NSArray
arrayWithObject:path]];
Try it with a script that has arguments on the shebang line, such
as "#!/usr/bin/perl -w -T", or a script that's been written to use
the first available interpreter in your path, like "#!/usr/bin/env
python".
OK, "launch path not accessible" in the run log. I take back
everything I said. Obviously I need to rethink this. I would like
the user to be able to include a script file without having to make
it executable. Earlier, I had a look to see if there is a way to
determine whether is file is executable, but didn't find one. I
suppose there must be a way but didn't see it in NSFileManager or
NSWorkspace.
Ron
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden