Re: running an external app
Re: running an external app
- Subject: Re: running an external app
- From: Roland King <email@hidden>
- Date: Tue, 27 May 2008 12:07:17 +0800
Take a look at the Overview section of the documentation, it has a
reasonable example in it of calling the Class Method to get the instance
and then calling an Instance Method on it to open a file with an
Application. The launchApplication() description is in the 'Instance
Methods' section.
I don't think there's much wrong with the documentation.
Overview
An |NSWorkspace| object responds to application requests to perform a
variety of services:
*
Opening, manipulating, and obtaining information about files and
devices
*
Tracking changes to the file system, devices, and the user database
*
Launching applications
There is one shared |NSWorkspace| object per application. You use the
class method |sharedWorkspace
<Reference.html#//apple_ref/occ/clm/NSWorkspace/sharedWorkspace>| to
access it. For example, the following statement uses an |NSWorkspace|
object to request that a file be opened in the TextEdit application:
[[NSWorkspace sharedWorkspace] openFile:@"/Myfiles/README"
withApplication:@"TextEdit"];
Johnny Lundy wrote:
True the OP needs to learn Objective-C. But let me just throw in here
one of my infamous objections to the documentation, namely the Class
Reference sections.
Here is the Class Reference documentation on NSWorkspace's
launchApplication: method:
launchApplication:
Launches the specified application.
- (BOOL)launchApplication:(NSString *)appName
Parameters
appName
The name of the application to open.
Return Value
YES if the application was successfully launched or was already
running; otherwise, NO.
Now the line
- (BOOL)launchApplication:(NSString *)appName
May be technically the declaration of the method, but is that really
useful to anybody? After all, you do not declare this method in your
code; you just invoke it. I can't tell you how many times I have been
led astray by this terminology - took me at least a year to figure
out that the way it is written has nothing to do with how you use it.
The way you would use it is something like
(BOOL) loadedIB = [[NSWorkspace sharedWorkSpace] launchApplication:
@"Interface Builder"];
Which bears no resemblance to the line that is written in the
documentation.
This OP is NEVER going to figure that out from the line in the
documentation. Even the "discussion" goes on and on about .app
extensions and what notifications the method sends, but never
mentions how to invoke the thing.
This is why they need to put at least one line in every one of these
method documentations to show how it is invoked.
I expect replies to the effect of "it would bloat the documentation",
etc., but the fact is, that single example could clarify 1) That you
have to message the sharedWorkspace instance, and 2) That you don't
actually code "- (BOOL)launchApplication:(NSString *)appName".
With the huge influx of new Cocoa programmers we are about to see,
Apple might give some thought to whipping up some example lines to
put in these "Class References." Every other reference manual I have
ever seen gives the metalanguage and also an example line.
That this OP's basically trying to copy the Reference text in his
code shows me that this confusion is very common.
<_< I still have the problem of invalid receiver type bool. The
program compiled but pressing the button did nothing. Please note that
the color of the word "bool" is not pink like it should be.
bool runApp;
whereas:
float firstNumber;
is pink.
I'm also having another problem.... how do I append a single digit to
an int like a calculator does? Again, I checked the documentation and
online but no luck. Am I missing some secret to searching the
documentation? Thanks!
_______________________________________________
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
_______________________________________________
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