Wednesday, November 22, 2017

#1 2011-07-20 10:40:28 pm

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

Lion changes

There's a page here that covers AppleScript and AppleScriptObjC in Lion: http://macosxautomation.com/lion/applescript.html

Obviously the ability to call C functions is a big change. And the ability to write AppleScriptObjC outside Xcode is good news. There are a couple of other changes, too:

* A crashing bug when returning structs like NSSize has been fixed (this appeared particularly in one of the window delegate resize methods).

* The behavior of class has changed. In 10.6, you could only ask for "class of..." with AS classes; with Cocoa classes you got an error, and you had to use |class|() instead. In Lion you can use "class of..." with Cocoa classes, too.

And there's lots of new Cocoa goodness to play with. NSRegularExpressions, hmmm. On the downside, Lion uses Xcode 4(.1), although there are claims that you can keep using Xcode 3 as long as it was installed before upgrading.

Of course, apps that use the new stuff will need to be marked as 10.7-only.


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

Offline

 

#2 2011-07-21 04:35:01 pm

Dave Higgins
Member
From:: Dark Side Of The Moon
Registered: 2010-03-27
Posts: 58

Re: Lion changes

Shane Stanley wrote:

Obviously the ability to call C functions is a big change....


I've been testing some of this out... The form of

Applescript:

tell current application to NSRectFill(aRect)

is working fine, even with my own custom function placed in it's own .h/.m set... But, I'm unable to find a solution to calling a function that should return data back to me... The following have all failed:

Applescript:

set tString to current application's testFunction()
tell current application to set tString to testFunction()
set tString to current application's testFunction("abc") -- modified function to take a param

All bring error: unrecognized function testFunction. (error -10000)

Any ideas how we can get data back from a C type function?

Dave.


Idiots are fun. No wonder every village wants one.

Offline

 

#3 2011-07-22 09:15:46 pm

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

Re: Lion changes

Dave,

Care to send me the sample?


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

Offline

 

#4 2011-07-23 02:36:57 am

tellboy
Member
Registered: 2005-06-23
Posts: 152

Re: Lion changes

This works for me

Applescript:

   on tester_(sender)

   beep -- this does not work see below
       set tRect to myTestFunction_()
       log tRect
   end tester_
   
   on myTestFunction_()
set tRect to current application's NSMakeRect(10,10,100,100)
return tRect
   end myTestFunction_

tRect is returned as :

{
    origin =     {
        x = 10;
        y = 10;
    };
    size =     {
        height = 100;
        width = 100;
    };
}


the beep above does not work it returns the following error:

doesn’t understand the «event sysobeep» message. (error -1708)
current application's NSBeep() does work

Offline

 

#5 2011-07-23 02:54:06 am

tellboy
Member
Registered: 2005-06-23
Posts: 152

Re: Lion changes

In addition how can you declare NSMakeRect so you do not have to keep typing:


current application's


All the best

Terry

Offline

 

#6 2011-07-23 03:44:37 am

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

Re: Lion changes

how can you declare NSMakeRect so you do not have to keep typing:

current application's


I don't see any way.

Interesting about beep, too, because it works in a Cocoa applet saved from AppleScript Editor or AppleScriptObjC Explorer.

You can also use:

Applescript:

tell current application to beep

It's a bit much when you have to work hard just to beep, though...


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

Offline

 

#7 2011-07-24 01:58:10 am

tellboy
Member
Registered: 2005-06-23
Posts: 152

Re: Lion changes

Hi,


beep used to work.

Do you know when we will get some documentation that informs us properly about all the changes?

I know, it's really to much to ask wink


All the best

Terry

Offline

 

#8 2011-07-24 02:38:26 am

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

Re: Lion changes

Do you know when we will get some documentation that informs us properly about all the changes?


I imagine official release notes will be out soon. But I don't expect to see much more detail than above.


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

Offline

 

#9 2011-07-26 03:45:06 pm

Dave Higgins
Member
From:: Dark Side Of The Moon
Registered: 2010-03-27
Posts: 58

Re: Lion changes

tellboy wrote:

This works for me

Applescript:

<snip>
       set tRect to myTestFunction_()
</snip>
   
on myTestFunction_()
<snip>
end myTestFunction_


What I'm talking about, Terry, is custom C-Style functions:

Applescript:

NSString* myFunction (NSString* aString)
{
return [aString uppercaseString];
}

and calling it with:


Applescript:


on testButton1Click_(sender)
set aString to "Test String 1"
set bString to current application's myFunction(aString)
-- RETURNS: *** -[MyAppAppDelegate testButton1Click:]: unrecognized function myFunction. (error -10000)
log bstring -- not reached
end testButton1Click_

Shane wrote:

Care to send me the sample?


Now, I'm having trouble even reproducing the one that worked which returned void. I'll see if I can re-create the working version, then send you one, Shane.

Last edited by Dave Higgins (2011-07-26 03:46:22 pm)


Idiots are fun. No wonder every village wants one.

Offline

 

#10 2011-07-26 07:50:00 pm

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

Re: Lion changes

I wonder if it's limited to functions defined in Cocoa. The problem I see is that without an equivalent of an #include statement, a script isn't going to know where to find a particular function. Presumably "current application's" has some search scope, and I wonder if it just looks up some table of known functions.

But I'm also a bit puzzled about why you would want to do this, rather than use a method. The only reason it's normally done in Objective-C is for speed, which is irrelevant here, and generally also when using C types rather than classes, also irrelevant to ASObjC.


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

Offline

 

#11 2011-07-26 10:11:10 pm

Dave Higgins
Member
From:: Dark Side Of The Moon
Registered: 2010-03-27
Posts: 58

Re: Lion changes

Shane Stanley wrote:

But I'm also a bit puzzled about why you would want to do this, rather than use a method.


Oh. It's not that I'm so dead set on needing custom functions. When working with pure Obj-C, I tend to write some wrappers as functions if I'm going to be calling on them a lot.

I do tend to mix the two (Obj-C and ASOC) now and then if I figure I'm going to be doing any AppleScript calls outside of the app, and sometimes I jump over to AS for certain text manipulations. I'm just looking forward to see what can be done from within ASOC with functions. That particular example I gave was just a simple "whip something up" for a test, and not a need for returning uppercaseString from a function.


Idiots are fun. No wonder every village wants one.

Offline

 

#12 2011-07-29 04:29:19 pm

Jonathan Mitchell
Member
From:: Northern Ireland
Registered: 2008-09-01
Posts: 9
Website

Re: Lion changes

Shane Stanley wrote:

I wonder if it's limited to functions defined in Cocoa. The problem I see is that without an equivalent of an #include statement, a script isn't going to know where to find a particular function. Presumably "current application's" has some search scope, and I wonder if it just looks up some table of known functions.


AppleScriptObjC knows about these functions because they are defined in the BridgeSupport xml data file that is included in the Cocoa framework bundle. Class information can generally be obtained dynamically but info regarding C structures, functions, enums, constants etc cannot. The BridgeSupport file defines the names and calling conventions for these C language elements.

You can produce a BridgeSupport file for any third party framework using gen_bridge_metadata

Offline

 

#13 2011-07-29 06:28:23 pm

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

Re: Lion changes

Ah, thank you very much, Jonathan. That explains a few things!


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

Offline

 

#14 2011-07-31 08:27:34 pm

carlcasca
Member
Registered: 2011-06-19
Posts: 8

Re: Lion changes

Hi Shane,

First, thank you for your four-part asobjc tutorials.  I'm still having trouble getting bindings to work in xcode 4, but without your tutorials, I'd barely even have gotten started with it.  I just upgraded to lion, and xcode 4.1 in hopes that the funny bindings behavior I see would be better.  Sadly it's worse.  In fact, your part2 and part4 asobjc tutorial codes do not run at all under lion and xcode-4.1 (or perhaps I've made a setup error).  These are your examples that read/write/modify a booklist.  The messages I get are shown below.  Any ideas on how to repair them would be greatly appreciated.

cheers,
     Carl

------- snipped message output------

GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Fri Jul  1 10:50:06 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
[Switching to process 3644 thread 0x0]
2011-07-31 21:18:29.200 PartFour[3644:707] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
PartFour: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
2011-07-31 21:18:29.317 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 1 into type boolean. (error -1700)
2011-07-31 21:18:29.319 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
2011-07-31 21:18:29.320 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
2011-07-31 21:18:29.322 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 1 into type boolean. (error -1700)
.
.
snip (many more lines like this)
-
-
-
2011-07-31 21:18:29.323 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
2011-07-31 21:18:29.324 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
2011-07-31 21:18:38.612 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
2011-07-31 21:18:38.613 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
2011-07-31 21:18:38.614 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 1 into type boolean. (error -1700)
2011-07-31 21:18:38.615 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
2011-07-31 21:18:38.617 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
2011-07-31 21:18:38.618 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 1 into type boolean. (error -1700)
2011-07-31 21:18:38.626 PartFour[3644:707] *** -[PartFourAppDelegate tableView:objectValueForTableColumn:row:]: Can’t make 0 into type boolean. (error -1700)
Program ended with exit code: 0

Offline

 

#15 2011-07-31 08:40:25 pm

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

Re: Lion changes

carlcasca wrote:

Hi Shane,

First, thank you for your four-part asobjc tutorials.


Thanks for the thanks, but you have the wrong person -- I think you're referring to Craig Williams's tutorials.

Not that that stops us from trying to solve your problem, but I'm a bit confused when you refer to bindings, because Craig's examples don't use bindings.

We need some more information, like what code is running when you get those errors.


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

Offline

 

#16 2011-08-02 10:37:20 am

carlcasca
Member
Registered: 2011-06-19
Posts: 8

Re: Lion changes

Hi,

Ahh, sorry, wrong person.  Yes, you're right, it's Craig Williams.  Well, the tutorial I'm referring to is here:
http://macscripter.net/viewtopic.php?id=30313 .  It's a simple booklist, and now that I've upgraded to lion and xcode 4.1, I can't even get it to run straight out of the box.

I was hoping someone else on Lion/xcode4.1 could have a go at it and see if it runs for them.  Perhaps there's something wrong with my install.

I downloaded this tutorial because I was having a terrible time trying to do what I think ought to be the hello-world equivalent of bindings: make a one-entry window that simply keeps the text in the window in sync with the code (i.e. a user could enter some text, the code could then append, say, "hello" to it, and that change made by the code would appear back in the window.  My (very limited) understanding of bindings makes me think this ought to be easy.

My plan was to take that part-2 tutorial and modify it so that did the above.  But sadly, it no longer runs at all.

Thanks again for any thoughts on this.  This forum is just plain fantastic, though it doesn't reflect too well on apple that they aren't even close to the leading source of documentation for their own code.

cheers,
    carl

P.S.  I've added what I think is relevant system info below

Model: macbook pro 15-inch, Mid 2010  Mac OS X Lion 10.7 (11A511)
AppleScript: xcode Version 4.1 (4B110)
Browser: Chrome 12.0.742.122
Operating System: Other

Offline

 

#17 2011-08-02 12:00:23 pm

fulmar2
Member
From:: Mountain View, CA
Registered: 2009-12-22
Posts: 14

Re: Lion changes

carlcasca -

Yes, I'm having the exact same problem.

Offline

 

#18 2011-08-02 12:22:21 pm

carlcasca
Member
Registered: 2011-06-19
Posts: 8

Re: Lion changes

ok, thanks for letting me know.  I posted over on the original topic so that perhaps Craig will see it.

Offline

 

#19 2011-08-02 05:56:19 pm

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

Re: Lion changes

The problem is in the script -- I'm not sure why it ever worked. This line:

Applescript:

   if ident's isEqualToString_("theStatus") then

should be like this:

Applescript:

   if (ident's isEqualToString_("theStatus")) as boolean then

Whenever you get a result from a Cocoa call, you need to coerce it to an AppleScript class before you can use it (with missing value arguably the exception).


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

Offline

 

#20 2011-08-02 08:11:29 pm

carlcasca
Member
Registered: 2011-06-19
Posts: 8

Re: Lion changes

I see.  Thank you for your help!

Offline

 

#21 2011-08-03 07:19:05 am

thewaytoapplescript
Member
Registered: 2011-05-30
Posts: 144

Re: Lion changes

I had the same problem and changed the isEqualToString line to the plain old AppleScript method

if ident = "theStatus" then


Works fine for me.


It depends on whether Apple wants to sell mass-market toasters, or computers; and Lion moved us a little bit in the direction of toasters. -partron22

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)