Date   

Re: Creating objects via AppleScript and setting readonly properties

Steve Mills
 

On May 10, 2019, at 18:31:43, Shane Stanley <sstanley@...> wrote:

On 11 May 2019, at 2:08 am, Steve Mills via Groups.Io <sjmills@...> wrote:

Is there any way to #include headers in an .sdef file so constants or #defines can be used and stringified?
It's just an XML file that gets added straight to the bundle, so I don't see how that would work.
Well, one could say the Info.plist is just a an xml file that gets added to the bundle, but it can be preprocessed. I use that feature a lot, like so the version number only has to be defined in one .h file and then can be used in the plist and other places. With there being so many AE constants, it would only make sense to allow sdef preprocessing to help prevent typos and mistakes.

--
Steve Mills
Drummer, Mac geek


Re: Creating objects via AppleScript and setting readonly properties

Shane Stanley
 

On 11 May 2019, at 2:08 am, Steve Mills via Groups.Io <sjmills@...> wrote:

Or do I need to implement -setId and have it return an error to AppleScript?
If there's another way, I don't know it.

Is there any way to #include headers in an .sdef file so constants or #defines can be used and stringified?
It's just an XML file that gets added straight to the bundle, so I don't see how that would work.

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


Re: Creating objects via AppleScript and setting readonly properties

Steve Mills
 

On May 10, 2019, at 11:08, Steve Mills via Groups.Io <sjmills@...> wrote:

Or is there something else I’m missing?
I did just find makeScriptingObjectOfClass or whatever it is (not at my desk now), so that’s a good way to ignore readonly properties. Still, seems like something should be doing that when letting the default methods handle it all.

Steve via iPad


Creating objects via AppleScript and setting readonly properties

Steve Mills
 

This seems like bug, or I need to override something. I have a class:

@interface Blah : NSObject
@property (readonly) NSUInteger id;
@end

The id property is exposed to AppleScript in the Blah class:

<property name=“id” code=“ID “ type=“integer” access=“r”>
<cocoa key=“id” />
</property>

If I make a new Blah like so:

make new blah at end of doc with properties {name:”Bob”, id:17}

The Blah is created and the id is happily set to 17. Shouldn’t something prevent that, either st the AppleScript level (access=“r”) or the Cocoa level ((readonly))?

Or do I need to implement -setId and have it return an error to AppleScript? Or is there something else I’m missing?

Oh, a side question. Is there any way to #include headers in an .sdef file so constants or #defines can be used and stringified? Seems problematic to have to type 4-char codes all through an sdef when the constants are already defined in private and Apple headers. I haven’t tried, but thought I’d ask, since I don’t see an Xcode setting for preprocessing sdefs or anything like that.

Steve via iPhone


Re: Adding scripting support for custom records

Steve Mills
 

On May 7, 2019, at 14:46:25, Alex Zavatone via Groups.Io <zav@...> wrote:

How do you plan to consume it? As an array, dictionary? You can even save it out as a pList and read it off media if you wish. You can even serialize it to JSON or XML. There even is serializing through NSCodable, but in this case, you would need to have the format to deserialize in your target app.

Actually, I wonder if you could use app groups and simply make the data common between apps running in that group or are you planning on accessing the data through scripting?
What? I think you misunderstood. This is purely AppleScript communication. Bill and Shane already confirmed I'm doing the right thing.

--
Steve Mills
Drummer, Mac geek


Re: Adding scripting support for custom records

Alex Zavatone
 

How do you plan to consume it? As an array, dictionary? You can even save it out as a pList and read it off media if you wish. You can even serialize it to JSON or XML. There even is serializing through NSCodable, but in this case, you would need to have the format to deserialize in your target app.

Actually, I wonder if you could use app groups and simply make the data common between apps running in that group or are you planning on accessing the data through scripting?

How do you wish to read the data in?

On May 6, 2019, at 10:42 PM, Steve Mills via Groups.Io <sjmills@...> wrote:

What's the best way to return data from a scriptable app when the property is a record-type that's declared in the sdef? It corresponds to an Objective-C class. I ended up adding a separate property to the owner class that returns the data in an NSDictionary and using that property in the sdef instead of the real property, which is the normal Objective-C class. But it feels like there should be a more simple way that I haven't been able to glean from the spotty documentation I've found so far.

I feel so dumb about this, having previously been about half responsible for implementing the AppleScript support and recordability for one of the best page layouts apps ever written back in the Carbon days.

--
Steve Mills
Drummer, Mac geek




Re: Adding scripting support for custom records

Steve Mills
 

On May 6, 2019, at 22:54:12, Shane Stanley <sstanley@...> wrote:

if I follow you correctly, that sounds about right. Cocoa scripting doesn't like simple records -- it wants custom record types.
OK, thanks for the confirmation. I was hoping there was something analogous to -objectSpecifier that I wasn't finding, such as -valueDdescriptor that would be called on the key-value object found at the object's property and return an NSAppleEventDescriptor.

--
Steve Mills
Drummer, Mac geek


Re: Selectable text in NSTableView?

John Brownie
 

Oops, yes. This was on the crash in dragImageForSelection.

Jens Alfke wrote on 6/5/19 20:02:



On May 6, 2019, at 7:15 AM, John Brownie <john_brownie@...> wrote:

Well, some further testing revealed that this was a way to make it work. It had the side benefit of making the window update more efficiently! Still, it would be nice to know why it was crashing in the first place...

I think that reply was meant for a different thread?

—Jens

--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: Adding scripting support for custom records

Shane Stanley
 

On 7 May 2019, at 1:42 pm, Steve Mills via Groups.Io <sjmills@...> wrote:

What's the best way to return data from a scriptable app when the property is a record-type that's declared in the sdef? It corresponds to an Objective-C class. I ended up adding a separate property to the owner class that returns the data in an NSDictionary and using that property in the sdef instead of the real property, which is the normal Objective-C class.
if I follow you correctly, that sounds about right. Cocoa scripting doesn't like simple records -- it wants custom record types.

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


Re: Adding scripting support for custom records

Bill Pitcher
 

I can’t add much other than I recall yours was the solution I used too.

Off-Topic
WWDC is very close and I’d be surprised if there aren’t significant changes to the whole Scripting shambles (I hope). YMMV

cheers
Bill

On 7 May 2019, at 1:42 pm, Steve Mills via Groups.Io <sjmills@...> wrote:

What's the best way to return data from a scriptable app when the property is a record-type that's declared in the sdef? It corresponds to an Objective-C class. I ended up adding a separate property to the owner class that returns the data in an NSDictionary and using that property in the sdef instead of the real property, which is the normal Objective-C class. But it feels like there should be a more simple way that I haven't been able to glean from the spotty documentation I've found so far.

I feel so dumb about this, having previously been about half responsible for implementing the AppleScript support and recordability for one of the best page layouts apps ever written back in the Carbon days.

--
Steve Mills
Drummer, Mac geek




Adding scripting support for custom records

Steve Mills
 

What's the best way to return data from a scriptable app when the property is a record-type that's declared in the sdef? It corresponds to an Objective-C class. I ended up adding a separate property to the owner class that returns the data in an NSDictionary and using that property in the sdef instead of the real property, which is the normal Objective-C class. But it feels like there should be a more simple way that I haven't been able to glean from the spotty documentation I've found so far.

I feel so dumb about this, having previously been about half responsible for implementing the AppleScript support and recordability for one of the best page layouts apps ever written back in the Carbon days.

--
Steve Mills
Drummer, Mac geek


Re: Selectable text in NSTableView?

 



On May 3, 2019, at 5:33 PM, Quincey Morris <quinceymorris@...> wrote:

In a similar recent scenario, I found it takes two clicks when the text field is selectable but not editable. (Well, one click and one drag, if you’re actually trying to select text.)

That’s the behavior I was getting the last time I worked on this app, a few months ago, but it’s somehow stopped working and I can’t get it to work again. Specifically, what used to work was
1. Click on row to select it
2. Mouse-down in text, drag horizontally
This no longer works, and I can’t get the text to select at all unless I change the NSTextField’s mode to Editable, which causes the problems I described earlier.

I haven’t done much with the table-related code since I had this working. I’m kind of suspecting some undocumented AppKit change in 10.14.4, but there are so many variables that can affect behavior that I’m not ready to file a bug report yet.

—Jens


Re: Selectable text in NSTableView?

 



On May 6, 2019, at 7:15 AM, John Brownie <john_brownie@...> wrote:

Well, some further testing revealed that this was a way to make it work. It had the side benefit of making the window update more efficiently! Still, it would be nice to know why it was crashing in the first place...

I think that reply was meant for a different thread?

—Jens


Re: Selectable text in NSTableView?

John Brownie
 

Well, some further testing revealed that this was a way to make it work. It had the side benefit of making the window update more efficiently! Still, it would be nice to know why it was crashing in the first place...

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: Crash in dragImageForSelection

John Brownie
 

Further experimentation reveals that the problem is (as far as I can tell) due to the code that handles a click updating the window. I seem to get a race condition: if I click, hold and drag, the drag image is created (though weirdly distorted to match the rect I supply), but a click and drag in one motion causes the crash.

Updating the window may cause the text view to get a new string supplied, so I'm guessing that it is somehow hitting the text view when the string is being replaced, causing the problem. How that happens, I'm not sure, since everything is on the main thread (since it's UI stuff), which shouldn't cause threading issues like I'm imagining.

Could I be on the right track here, or what else could the problem be?

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: Selectable text in NSTableView?

Quincey Morris
 

On May 3, 2019, at 14:52 , Jens Alfke <jens@...> wrote:

If I set the “selectable” property of the NSTextField, nothing happens.

In a similar recent scenario, I found it takes two clicks when the text field is selectable but not editable. (Well, one click and one drag, if you’re actually trying to select text.)

What makes this seem unresponsive is that there’s no I-beam cursor in selectable-but-not-editable mode. It’s there but invisible after a second click (you can even move its — invisibly — with the arrow keys), but your brain resists believing it.

The reality is, it’s probably better to go ahead and subclass NSTableView and force it to pass the first click (or first drag, more likely) to the text field. I haven’t tried to do it yet, but I think there’s no built in behavior that isn’t going to make you angry on an ongoing basis.


Re: Selectable text in NSTableView?

Alex Zavatone
 

Wild guess, but what about the “can” methods.

In the headers is there any hidden secret docs hat might help?

On May 3, 2019, at 4:52 PM, Jens Alfke <jens@...> wrote:

I’ve got a view-based NSTableView that uses NSTextFields. I’d like to be able to select text in some of the columns, mostly so it can be copied to the pasteboard.

If I set the “selectable” property of the NSTextField, nothing happens.
If I set the “editable” property, I can select text … but the text field immediately becomes editable when the row is clicked to select it (i.e. its background changes to white and a focus ring is drawn around it.)

I’d prefer to have the field become editable on a second click, after selecting the row. But I can’t think of a clean way of doing this without a bunch of gnarly AppKit subclassing and method-overriding. Any suggestions?

—Jens

PS: This is *MAC OS*, not iOS.


Selectable text in NSTableView?

 

I’ve got a view-based NSTableView that uses NSTextFields. I’d like to be able to select text in some of the columns, mostly so it can be copied to the pasteboard.

If I set the “selectable” property of the NSTextField, nothing happens.
If I set the “editable” property, I can select text … but the text field immediately becomes editable when the row is clicked to select it (i.e. its background changes to white and a focus ring is drawn around it.)

I’d prefer to have the field become editable on a second click, after selecting the row. But I can’t think of a clean way of doing this without a bunch of gnarly AppKit subclassing and method-overriding. Any suggestions?

—Jens

PS: This is *MAC OS*, not iOS.


Re: Crash in dragImageForSelection

John Brownie
 

Gary L. Wade wrote on 27/4/19 02:07:
The bug in documentation has been reported.

Try forcing layout on the text view after setting the selection; there might be some kind of delay from setting it till it’s renderable, and that might get it refreshed.
Doesn't seem to help.
On Apr 26, 2019, at 11:51 AM, Ben Kennedy <ben-groups@...> wrote:


First of all, you're treating textView as an optional sometimes, and force-unwrapping it elsewhere. Prefacing the whole block with a `guard` or `if let` would clean this up.
Yes, it's a result of various ways of setting the range correctly. I've fixed it so it looks nicer.
More on topic, I looked up the documentation for `setSelectedRange()`, and it is strange:

https://developer.apple.com/documentation/appkit/nstextview/1449256-setselectedrange?language=objc

charRange: A non-nil, non-empty array of objects responding to the NSValue rangeValue method. The ranges in the ranges array must begin and end on glyph boundaries and not split base glyphs and their nonspacing marks.
The method clearly takes an NSRange argument, but the documentation instead talks about an array of NSValue objects. WTH? I guess this is a documentation error? (Somebody file a radar... crickets)

If you call `selectedRange` immediately after `setSelectionRange(…)`, does it reflect the range you tried to set?
Yes, the range is correct after calling setSelectedRange.

I wonder if the answer is to draw my own drag image...

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: Crash in dragImageForSelection

Gary L. Wade
 

The bug in documentation has been reported.

Try forcing layout on the text view after setting the selection; there might be some kind of delay from setting it till it’s renderable, and that might get it refreshed.
--
Gary L. Wade
http://www.garywade.com/

On Apr 26, 2019, at 11:51 AM, Ben Kennedy <ben-groups@...> wrote:


On 26 Apr 2019, at 4:26 am, John Brownie <john_brownie@...> wrote:

I have what seems to be a simple operation to perform, but it crashes. I have a custom view which includes an NSTextView called textView. In the mouseDragged(with:) function in my view subclass, I have the following code (leaving out the logic deciding whether it is appropriate as a drag source):

textView?.setSelectedRange(NSMakeRange(0, textView!.textStorage!.length))
let dragImage = textView?.dragImageForSelection(with: event, origin: nil)
I don't have any useful help for you, but a couple of things struck me as odd about this.

First of all, you're treating textView as an optional sometimes, and force-unwrapping it elsewhere. Prefacing the whole block with a `guard` or `if let` would clean this up.

More on topic, I looked up the documentation for `setSelectedRange()`, and it is strange:

https://developer.apple.com/documentation/appkit/nstextview/1449256-setselectedrange?language=objc

charRange: A non-nil, non-empty array of objects responding to the NSValue rangeValue method. The ranges in the ranges array must begin and end on glyph boundaries and not split base glyphs and their nonspacing marks.
The method clearly takes an NSRange argument, but the documentation instead talks about an array of NSValue objects. WTH? I guess this is a documentation error? (Somebody file a radar... crickets)

If you call `selectedRange` immediately after `setSelectionRange(…)`, does it reflect the range you tried to set?

b

521 - 540 of 1457