trying to open a application that is stored in my Xcode application

script FORMULA
    on OpenFormula_(sender)
        set posixPath to (current application's NSBundle's mainBundle's pathForResource:"FORMULA" ofType:"app") as string
        set posfile to (posixPath as string) as POSIX file
        set FP_1 to posfile as string
        open FP_1
        activate
    end OpenFormula_
end script

Hi
I am trying to open an application that is stored in my Xcode application using the above, but it errors with

AppleEvent timed out. (error -1712)

the code above works fine opening .applescript files from within my app, but not this one, do I need
to change this approach to do what I need?, if so to what please?, thanks for any help.

edit: another error thrown was the document ā€œFormulaā€ could not be opened, MY APP cannot open files
in the ā€œapplicationā€ format.

If itā€™s an application, you surely want to run it, not open it.

cheers Shane

thatā€™s where I was going wrong

I ended up with this

set FP_ to (current application's NSBundle's mainBundle's pathForResource:"Formula" ofType:"app") as string
       run application FP_
       activate application "Formula"

why not going the entire Cocoa way?


      set appURL to current application's NSBundle's mainBundle's URLForResource:"FORMULA" withExtension:"app"
      current application's NSWorkspace's sharedWorkspace()'s launchApplicationAtURL: appURL options:0 configuration:(missing value) |error|:(missing value)

I have this error:
-[NSWorkspace launchApplicationAtURL:options:configuration:]: unrecognized selector sent to instance 0x600000208360 (error -10000)

:confused:

The following code works for me:

set appURL to quoted form of ((current application's NSBundle's mainBundle()'s pathForResource_ofType_("FORMULA", "app")) as string)
do shell script "open -a " & appURL

Sorry, I missed the error parameter.
Itā€™s now fixed in the post above

When compiling:

error: Expected end of line, etc. but found ā€œerrorā€. (-2741)

I should have tested the code.

Missed the pipes around error because error is a reserved word in AppleScript

This code works:

:cool: