Re: Points vs pixels in a bash script

2020-06-08 Thread Jeff Younker via Cocoa-dev
Just as an aside, points are not Apple-specifc. They are a typesetting unit
equivalent to 1/72 of an inch. It's the same unit used for font sizes.

-jeff


On Mon, Jun 8, 2020 at 2:43 PM Gabriel Zachmann via Cocoa-dev <
cocoa-dev@lists.apple.com> wrote:

> I know this mailing list might not be the perfect fit for my question,
> but maybe someone has an idea.
>
> I have a problem converting points (I think) to pixels in a bash script.
> I'd rather not write an extra C/Cocoa utility for that.
>
> Using
>system_profiler SPDisplaysDataType
> I can retrieve the size of a Mac's display in pixels.
>
> However, the command
>
>tell application "System Events" to get the size of every window of
> every process
>
> (which I execute from my bash script using osascript) apparently does NOT
> return window sizes in pixels. I guess it's the strange "Apple points"
> units. According to my experiments, on my MacBook Pro Retina, for instance,
> a fullscreen app (e.g., Keynote presentation) has a window size of 1680 x
> 1050.
> By contrast, system_profiler reports 2880 x 1800.
>
> So, the question is: how can I determine the screen size of a Mac from my
> bash script in the same units like "System Events" uses?
> Or, how can I determine the factor by which I have to convert pixels into
> those other units?
>
>
> Many thanks in advance for any insights or hints.
>
> Best regards, Gabriel
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/jeff%40drinktomi.com
>
> This email sent to j...@drinktomi.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


What is the preferred way to set NSTextView content from NSAttributedString?

2020-02-02 Thread Jeff Younker via Cocoa-dev
Situation:

   - I am working in Swift 5.
   - I have an instance of an NSTextView. (Call it "V")
   - The value has already been set once. (Call this value "T1")
   - V is showing T1.
   - I have an NSAttributedString from another source. (Call this value
   "T2")

Desired goal:

   - I want to set the displayed contents of V to T2.

What is/are the recommended way/s to do this?

*I would hope that I could assign V.attributedString = T2, but alas the
world does not seem to be this simple.*

Thanks in advance.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Preferred methods for usig NSOutlineView

2019-12-18 Thread Jeff Younker via Cocoa-dev
I've been playing around with the NSOutlineView, and as seems to be the
usual case, the documentation from Apple is seriously deficient.

I've been trying to use bindings to a tree controller, but I'm having
difficulty getting element selection to work. I'm guessing that this would
be done by binding to the tree controller using "Selection Index Paths
(...)", but exactly what needs to be done there is unclear.

Is there a worked-through example using interface builder and
outlineview-treecontroller bindings, or should I give up on bindings and
start using NSOutlineViewDelegate and rampant NSOutlineView subclassing?

-jeff
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Difficulties with recovering NSAttributedString attachments from saved RTFD

2019-11-27 Thread Jeff Younker via Cocoa-dev
So, I replaced...

*let* recoveredString = NSMutableAttributedString(rtfd: savedRtfd,
documentAttributes: *nil*)!
...with...

*let* fw = FileWrapper(serializedRepresentation: savedRtfd)!

*let* filePath = URL(fileURLWithPath: "/tmp/bar")

*do* {

*try* fw.write(

to: filePath,

options: [FileWrapper.WritingOptions.atomic],

originalContentsURL: *nil*)

} *catch* {

print("Error info: \(error)")

XCTFail()

}

*let* recoveredString = NSMutableAttributedString(rtfdFileWrapper:
fw, documentAttributes: *nil*)!


The RTFD gets unpacked into /tmp/bar/..., and I can see the file with the
appropriate contents:


> cat /tmp/bar/Attachment.txt

foobar

>


*Bad News*

recoveredAttachment.contents is still nil.


*Good News*

Going through the attachment's file wrapper works:


   let recoveredContents = recoveredAttachment.fileWrapper?.
regularFileContents

   XCTAssertEqual(String(data: recoveredContents!, encoding: .utf8),
"foobar")


*Even Better News*

Going through the attachment's file wrapper works when using the original
code. (!!)

*Conclusion*

NSTextAttachment.contents seems to be broken, deeply misleading, or (most
likely) some other magic is required to get it to read its contents.


Thank you for pointing me in the right direction Gary.


-jeff

On Wed, Nov 27, 2019 at 8:35 PM Gary L. Wade 
wrote:

> You want to use a file wrapper rather than data and specify the document
> type in the attributes as RTFD.
> --
> Gary L. Wade
> http://www.garywade.com/
>
> On Nov 27, 2019, at 10:18 AM, Jeff Younker via Cocoa-dev <
> cocoa-dev@lists.apple.com> wrote:
>
> I am having some difficulty with saving NSAttributedStrings as RTFD and
> then recovering
> them with attachments intact.  I generate a string containing an attachment
> and turn that into
> RTFD. When I turn that RTFD back into an NSAttributedString, I get the
> .string back, and I
> get an attachment, but the attachment's .contents is empty.
>
> This is the smallest example I can come up with:
>
> func testSaveAndRestoreAttachment() {
>  // Build up the string "deadbeefdeadbeef"
>  let originalContent = "foobar".data(using: .utf8)
>  let originalAttachment = NSTextAttachment(
>data: originalContent, ofType: "public.plain-text")
>  let originalString = NSMutableAttributedString(string: "deadbeef")
>  originalString.append(NSMutableAttributedString(attachment:
> originalAttachment))
>  originalString.append(NSMutableAttributedString(string: "deadbeef")
>
>  // save string as RTFD (note that generated RTFD contains "foobar"
> inside.)
>  let savedRtfd = originalString.rtfd(from:
> NSRange(0..
>  // Recover string
>  let recoveredString = NSAttributedString(rtfd: savedRtfd,
> documentAttributes: nil)!
>  // Implementation of attachments() can be found below.
>  let recoveredAttachments = attachments(from: recoveredString)
>  // There *is* an attachment!
>  let recoveredAttachment = recoveredAttachments[0]
>  // Want to get Data("foobar") but actually get nil :(
>  XCTAssertNotNil(recoveredAttachment.contents)
> }
>
> When I print out the RTFD I can see the document includes the attachment
> "foobar".
>
> I'm assuming that I need to pass some additional information when I
> call NSAttributedString(rtfd:,
> documentAttributes:)
> but I'm at a loss here.
>
> Am I missing something simple? Perhaps a magical setting to be passed in
> documentAttributes?
>
> -jeff
>
>
>
> ** This is the attachments() function used above:
>
> func attachments(from s: NSAttributedString) -> Array {
>var attachments: Array = []
>s.enumerateAttribute(.attachment, in: NSRange(0..value, range, stop in
>guard let a = value else {
>   return
>}
>attachments.append(a as! NSTextAttachment)
>}
>return attachments
> }
>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Difficulties with recovering NSAttributedString attachments from saved RTFD

2019-11-27 Thread Jeff Younker via Cocoa-dev
I am having some difficulty with saving NSAttributedStrings as RTFD and
then recovering
them with attachments intact.  I generate a string containing an attachment
and turn that into
RTFD. When I turn that RTFD back into an NSAttributedString, I get the
.string back, and I
get an attachment, but the attachment's .contents is empty.

This is the smallest example I can come up with:

func testSaveAndRestoreAttachment() {
  // Build up the string "deadbeefdeadbeef"
  let originalContent = "foobar".data(using: .utf8)
  let originalAttachment = NSTextAttachment(
data: originalContent, ofType: "public.plain-text")
  let originalString = NSMutableAttributedString(string: "deadbeef")
  originalString.append(NSMutableAttributedString(attachment:
originalAttachment))
  originalString.append(NSMutableAttributedString(string: "deadbeef")

  // save string as RTFD (note that generated RTFD contains "foobar"
inside.)
  let savedRtfd = originalString.rtfd(from:
NSRange(0.. Array {
var attachments: Array = []
s.enumerateAttribute(.attachment, in: NSRange(0..https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com