Friday, December 15, 2017

#1 2015-09-15 05:22:15 pm

Budgie
Member
From:: New Zealand
Registered: 2005-02-22
Posts: 643

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

Applescript:

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.

Last edited by Budgie (2015-09-15 05:25:20 pm)


Budgie

"Our greatest glory is not in never falling, but in rising every time we fall"    - Batman

Offline

 

#2 2015-09-15 07:39:33 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

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

If it's an application, you surely want to run it, not open it.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2015-09-15 07:52:53 pm

Budgie
Member
From:: New Zealand
Registered: 2005-02-22
Posts: 643

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

cheers Shane

that's where I was going wrong


I ended up with this

Applescript:

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


Budgie

"Our greatest glory is not in never falling, but in rising every time we fall"    - Batman

Offline

 

#4 2015-09-16 01:28:59 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

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

why not going the entire Cocoa way?

Applescript:


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)

Last edited by StefanK (2015-09-26 06:25:10 am)


regards

Stefan

Offline

 

#5 2015-09-26 05:28:40 am

Titanium
Member
From:: ~/Desktop
Registered: 2005-08-22
Posts: 43
Website

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

StefanK wrote:

why not going the entire Cocoa way?

Applescript:


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


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

hmm

The following code works for me:

Applescript:

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


iMac 27" 3,4 Ghz - macOS High Sierra
https://www.titanium-software.fr

Offline

 

#6 2015-09-26 05:47:14 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

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

Sorry, I missed the error parameter.
It's now fixed in the post above


regards

Stefan

Offline

 

#7 2015-09-26 06:19:23 am

Titanium
Member
From:: ~/Desktop
Registered: 2005-08-22
Posts: 43
Website

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

StefanK wrote:

Applescript:


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)


When compiling:

error: Expected end of line, etc. but found “error”. (-2741)


iMac 27" 3,4 Ghz - macOS High Sierra
https://www.titanium-software.fr

Offline

 

#8 2015-09-26 06:26:24 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

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

I should have tested the code…

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


regards

Stefan

Offline

 

#9 2015-09-26 07:20:55 am

Titanium
Member
From:: ~/Desktop
Registered: 2005-08-22
Posts: 43
Website

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

This code works:

set appURL to (current application's NSBundle's mainBundle()'s pathForResource_ofType_("FORMULA", "app") as string)
current application's NSWorkspace's sharedWorkspace()'s launchApplication: appURL


cool

Last edited by Titanium (2015-09-26 07:22:01 am)


iMac 27" 3,4 Ghz - macOS High Sierra
https://www.titanium-software.fr

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)