Monday, April 22, 2019

#1 2018-12-13 04:25:19 am

kate
Member
Registered: 2018-12-11
Posts: 2

Open GC window in one .applescript file and work with it in another

Hello!

I'm trying to open Google Chrome in my app and run a test suite on it.

I have two .applescript files in my project:

AppDelegate

Applescript:

script AppDelegate
   property parent : class "NSObject"
   
   -- IBOutlets
   property theWindow : missing value
property AnotherAppleScript: missing value

   on applicationWillFinishLaunching_(aNotification)
set newWindow to (current application's AnotherAppleScript's launchGoogleChrome())

tell application "Google Chrome"
set windowID to id of newWindow
set URL of (its window id windowID)'s first tab to "http://example.com"
end tell
   end applicationWillFinishLaunching_
   
   on applicationShouldTerminate_(sender)
       -- Insert code here to do any housekeeping before your application quits
       return current application's NSTerminateNow
   end applicationShouldTerminate_
   
end script

AnotherAppleScript

Applescript:

script AnotherAppleScript

property parent : class "NSObject"

on launchGoogleChrome()
tell application "Google Chrome"
set newWindow to make new window with properties {mode:"normal"}
return newWindow
end tell
end launchGoogleChrome
end script

I receive this error:
2018-12-13 14:11:44.963858+0400 Test[52350:13077959] *** -[AppDelegate applicationWillFinishLaunching:]: Can’t get id of «class ocid» id «data optr00000000C08B2F0000600000». (error -1728)

Why?

Everything is fine if I try to do it in one file.

Offline

 

#2 2018-12-13 05:00:29 am

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

Re: Open GC window in one .applescript file and work with it in another

You can't return AppleScript objects from methods that are called by another object in an Xcode app. You're effectively calling an Objective-C class method on an Objective-C class (AnotherAppleScript), and the method must return a Cocoa object.

Try passing the window's id instead; the scripting bridge can then wrap that in an NSNumber. Just remember to coerce it back to an integer in the calling code.


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

Offline

 

#3 2018-12-13 05:45:00 am

kate
Member
Registered: 2018-12-11
Posts: 2

Re: Open GC window in one .applescript file and work with it in another

Oh thank you very much, it works!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)