Discussion:
A reliable way to open an app programmatically?
(too old to reply)
Fortepianissimo
2005-02-11 01:32:55 UTC
Permalink
I'd like to launch my own app inside another piece of code. I've tried
-[NSWorkspace openFile:] and -[NSWorkspace launchApplication:], even
started an NSTask using "/usr/bin/open". But the problem is, whenever
I build my app and *before* I double-click on the app the first time,
the above methods always fail.

(I remember a while ago that in order to combat against a document
spoofing problem, Apple made launching an app through a document more
discrimitive (by presenting users a dialog asking for confirmation). I
wonder if it is the cause of my problem.)

For example, using -[NSWorkspace openFile:] would give me

LSOpenFromURLSpec() returned -10814 for application (null) path
/the/path/to/my/app.app.

Is there any way to work around this problem? Thank you.
Fortepianissimo
2005-02-11 01:32:55 UTC
Permalink
I'd like to launch my own app inside another piece of code. I've tried
-[NSWorkspace openFile:] and -[NSWorkspace launchApplication:], even
started an NSTask using "/usr/bin/open". But the problem is, whenever
I build my app and *before* I double-click on the app the first time,
the above methods always fail.

(I remember a while ago that in order to combat against a document
spoofing problem, Apple made launching an app through a document more
discrimitive (by presenting users a dialog asking for confirmation). I
wonder if it is the cause of my problem.)

For example, using -[NSWorkspace openFile:] would give me

LSOpenFromURLSpec() returned -10814 for application (null) path
/the/path/to/my/app.app.

Is there any way to work around this problem? Thank you.
Kevin Ballard
2005-02-11 01:42:04 UTC
Permalink
That error code means the application is not found in the
LaunchServices database, so your analysis of the cause may in fact be
correct.
Post by Fortepianissimo
I'd like to launch my own app inside another piece of code. I've tried
-[NSWorkspace openFile:] and -[NSWorkspace launchApplication:], even
started an NSTask using "/usr/bin/open". But the problem is, whenever
I build my app and *before* I double-click on the app the first time,
the above methods always fail.
(I remember a while ago that in order to combat against a document
spoofing problem, Apple made launching an app through a document more
discrimitive (by presenting users a dialog asking for confirmation). I
wonder if it is the cause of my problem.)
For example, using -[NSWorkspace openFile:] would give me
LSOpenFromURLSpec() returned -10814 for application (null) path
/the/path/to/my/app.app.
--
Kevin Ballard
***@sb.org
http://www.tildesoft.com
http://kevin.sb.org
Fortepianissimo
2005-02-11 01:49:20 UTC
Permalink
Yes the funny thing is, right after this error, if I single-click the
app (i.e., not launching it), and run the same code again, it would
work. It's as if the launch service "learns" the existence of the app
by the mere act of single-clicking (but it has to be *after* my code
tries to open it).
Post by Kevin Ballard
That error code means the application is not found in the
LaunchServices database, so your analysis of the cause may in fact be
correct.
Post by Fortepianissimo
I'd like to launch my own app inside another piece of code. I've tried
-[NSWorkspace openFile:] and -[NSWorkspace launchApplication:], even
started an NSTask using "/usr/bin/open". But the problem is, whenever
I build my app and *before* I double-click on the app the first time,
the above methods always fail.
(I remember a while ago that in order to combat against a document
spoofing problem, Apple made launching an app through a document more
discrimitive (by presenting users a dialog asking for confirmation). I
wonder if it is the cause of my problem.)
For example, using -[NSWorkspace openFile:] would give me
LSOpenFromURLSpec() returned -10814 for application (null) path
/the/path/to/my/app.app.
--
Kevin Ballard
http://www.tildesoft.com
http://kevin.sb.org
Richard Rothwell
2005-02-11 02:21:38 UTC
Permalink
Does running this code prior to launching the app
improve things??

[[NSWorkspace sharedWorkspace] noteFileSystemChanged];
Post by Fortepianissimo
Yes the funny thing is, right after this error, if I single-click the
app (i.e., not launching it), and run the same code again, it would
work. It's as if the launch service "learns" the existence of the app
by the mere act of single-clicking (but it has to be *after* my code
tries to open it).
Dr Richard Rothwell (BSc-Hons, DipEd, PhD)
Faraday R&D
Google: Macintosh contractor Australia
http://www.farad.com.au/
***@farad.com.au
Educational software developer for Mac/Win/Web/CDROM
Kevin Ballard
2005-02-11 04:12:18 UTC
Permalink
AFAIK, that method is simply to inform the Finder to update all of its
open windows.
Post by Richard Rothwell
Does running this code prior to launching the app
improve things??
[[NSWorkspace sharedWorkspace] noteFileSystemChanged];
--
Kevin Ballard
***@sb.org
http://www.tildesoft.com
http://kevin.sb.org
Fortepianissimo
2005-02-11 04:48:02 UTC
Permalink
It's getting weird. With -noteFileSystemChanged, sometimes it works
and sometimes it doesn't. More weird is, without that, now it becomes
working again every single time - even after I got the same error
message

LSOpenFromURLSpec() returned -10814 for application (null) path
/path/to/myApp.app

(I use -[NSWorkspace openFile:] ).

Looks like there's some funny irregularity as to whether launch
service can or cannot find the newly built app.

In short, I'm still puzzled.
Post by Kevin Ballard
AFAIK, that method is simply to inform the Finder to update all of its
open windows.
Post by Richard Rothwell
Does running this code prior to launching the app
improve things??
[[NSWorkspace sharedWorkspace] noteFileSystemChanged];
--
Kevin Ballard
http://www.tildesoft.com
http://kevin.sb.org
Chaz McGarvey
2005-02-11 05:23:15 UTC
Permalink
Post by Fortepianissimo
It's getting weird. With -noteFileSystemChanged, sometimes it works
and sometimes it doesn't. More weird is, without that, now it becomes
working again every single time - even after I got the same error
message
LSOpenFromURLSpec() returned -10814 for application (null) path
/path/to/myApp.app
(I use -[NSWorkspace openFile:] ).
Looks like there's some funny irregularity as to whether launch
service can or cannot find the newly built app.
In short, I'm still puzzled.
This is probably very unrelated, but I have also noticed that
NSWorkspace is not always very consistent. In particular, the
notification NSWorkspaceWillLaunchApplicationNotification is not always
sent. I haven't been able discover the circumstances which cause this
failure, but it is quite annoying.


Chaz McGarvey
http://www.brokenzipper.com
Kevin Ballard
2005-02-11 04:54:24 UTC
Permalink
You could try using lsregister
(/System/Library/Frameworks/ApplicationServices.framework/Frameworks/
LaunchServices.framework/Support/lsregister) in a script phase (set
last in the target's phases) to force LaunchServices to re-register
your application.
Post by Fortepianissimo
It's getting weird. With -noteFileSystemChanged, sometimes it works
and sometimes it doesn't. More weird is, without that, now it becomes
working again every single time - even after I got the same error
message
LSOpenFromURLSpec() returned -10814 for application (null) path
/path/to/myApp.app
(I use -[NSWorkspace openFile:] ).
Looks like there's some funny irregularity as to whether launch
service can or cannot find the newly built app.
In short, I'm still puzzled.
--
Kevin Ballard
***@sb.org
http://www.tildesoft.com
http://kevin.sb.org
Finlay Dobbie
2005-02-11 18:49:16 UTC
Permalink
Post by Kevin Ballard
You could try using lsregister
(/System/Library/Frameworks/ApplicationServices.framework/Frameworks/
LaunchServices.framework/Support/lsregister) in a script phase (set
last in the target's phases) to force LaunchServices to re-register
your application.
Or you could use LSRegisterURL (as of 10.3, see LSInfo.h)

-- Finlay
Shawn Erickson
2005-02-11 19:24:26 UTC
Permalink
Post by Finlay Dobbie
Post by Kevin Ballard
You could try using lsregister
(/System/Library/Frameworks/ApplicationServices.framework/Frameworks/
LaunchServices.framework/Support/lsregister) in a script phase (set
last in the target's phases) to force LaunchServices to re-register
your application.
Or you could use LSRegisterURL (as of 10.3, see LSInfo.h)
As a side note I didn't have much luck using it after updating an
application with a patching tool to pickup new version information,
etc.

Of course I never had time to go back an figure out exactly why
however...

-Shawn
Fortepianissimo
2005-02-11 20:44:16 UTC
Permalink
Thanks - by far this seems to be the most reliable way. I haven't seen
any one failure case.


On Fri, 11 Feb 2005 18:49:16 +0000, Finlay Dobbie
Post by Finlay Dobbie
Post by Kevin Ballard
You could try using lsregister
(/System/Library/Frameworks/ApplicationServices.framework/Frameworks/
LaunchServices.framework/Support/lsregister) in a script phase (set
last in the target's phases) to force LaunchServices to re-register
your application.
Or you could use LSRegisterURL (as of 10.3, see LSInfo.h)
-- Finlay
Continue reading on narkive:
Loading...