I'm browsing the forum with a hope I'll find a mention to `requestAuthorization` API and how to use it. Didn't find any yet. Do you mind to point me to one of many many existing questions with an answer to that maybe?eg. I see this https://forums.developer.apple.com/thread/127371 that says one strategy is to use `NSWorkspaceAuthorization` that is exactly what I'm trying to use, yet I'm failing.
Post
Replies
Boosts
Views
Activity
> /usr/local is only for open source software ported to the Mac.that's not true/usr/local/bin is for local binaries
it's off-topic now, however /Applications is for app bundles, that's different than /usr/local/bin that is part of PATH env. and is a place for CLI binaries for local users.
Thank you.If you read my sample code from the initial post, you'll see that I'm trying to create a symlink in /usr/local/bin. /usr/local/bin is there by default, it comes from BSD origins of macOS afair and is in PATH by default. that makes it a perfect place for many CLI tools (and is used for that purpose by many)
I wanted to update it (after 5 years) that NSView.updateLayer() is still not called despite all the magic:
override var wantsUpdateLayer: Bool { true }
wantsLayer = true
layerContentsRedrawPolicy = .onSetNeedsDisplay
override func makeBackingLayer() -> CALayer {
		CATextLayer()
}
without custom makeBackingLayer, updateLayer() is called.
According to Managing Pop-Up Buttons and Pull-Down Lists - https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MenuList/Articles/ManagingPopUpItems.html this is expected behavior
Unlike popup lists, the title of a popup button displaying a pulldown list is not based on the currently selected item and thus remains fixed unless you change using the cell’s setTitle:method.
I noticed the same problem (reported FB8820682).
Sample view to reproduce: https://gist.github.com/krzyzanowskim/1ca0e13edec6fd43d235d0a344f831b8 if anyone care.
I see it macOS 11.0 (20A5395g), Xcode 12.2 beta 3 (12B5035g).
And indeed (as @kai_2 said), clip is still set! that is very strange.
You can check README for AES examples: https://github.com/krzyzanowskim/CryptoSwift#aes
the simplest form is this one-liner:
let encrypted = try AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7).encrypt(plaintext)
AES-256 requires 32 bytes long key.
More complete example (AES-256-CBC), with a key generation out of password would be something along the lines.
let password: [UInt8] = Array("s33krit".utf8)
let salt: [UInt8] = Array("nacllcan".utf8)
/* Generate a key from a `password`. Optional if you already have a key */
let key = try PKCS5.PBKDF2(
		password: password,
		salt: salt,
		iterations: 4096,
		keyLength: 32, /* AES-256 */
		variant: .sha256
).calculate()
/* Generate random IV value. IV is public value. Either need to generate, or get it from elsewhere */
let iv = AES.randomIV(AES.blockSize)
/* AES cryptor instance */
let aes = try AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7)
/* Encrypt Data */
let inputData = Data()
let encryptedBytes = try aes.encrypt(inputData.bytes)
let encryptedData = Data(encryptedBytes)
/* Decrypt Data */
let decryptedBytes = try aes.decrypt(encryptedData.bytes)
let decryptedData = Data(decryptedBytes)
beside README, there's playground you can take a look at CryptoSwift.playground - https://github.com/krzyzanowskim/CryptoSwift/blob/8ee88c7587be82a7c8ec0de4f882628a4f3768e5/CryptoSwift.playground/Contents.swift#L92
I'm here just to note that I also noticed this behavior. As soon as I set "doubleAction" on NSOutlineView, the cell start editing after first tap. This is macOS 11 so I assume if it hasn't been fixed by now, we have to deal with it.
maybe this year? who knows 🤞🤞
I tested this with the sample app provided by Apple from https://developer.apple.com/documentation/fileprovider/macos_support/syncing_files_on_macos and as soon as I modify it to signal anything else than workingSet, signaling stop working.
I tried to signal using fileproviderctl CLI tool, and the effect is the same. only working set container is triggered
This problem is reported with number FB9673209
It's still documented as available in macOS 12. How it can be "works as designed" and not supported at the same time?
Reported as FB9728793
Use NSTextView.textSelections, then use NSTextLayoutManager to get the position of a first selection NSTextRange and frame
let selectionTextLocation = textSelections.flatMap(\.textRanges)[0].location
next find a frame
textLayoutManager.enumerateSegments(in: NSTextRange(location: selectionTextLocation), type: .standard, options: .upstreamAffinity) { _, segmentFrame, baselinePosition, _ in
// use segmentFrame and baselinePosition to calculate insertion point location in NSTextContainer
}
I don't know if this is recommended, however since nobody picked up this questions, this is what I do:
I assume you use NSRulerView as an NSScrollView.verticalRulerView property. What I do, is override drawHashMarksAndLabels(in:) and use CoreText to draw numbers in the positions from NSTextLayoutManager
class LineNumberRulerView: NSRulerView {
private weak var textView: NSTextView?
init(textView: NSTextView) {
self.textView = textView
super.init(scrollView: textView.enclosingScrollView!, orientation: .verticalRuler)
clientView = textView.enclosingScrollView!.documentView
NotificationCenter.default.addObserver(forName: NSView.frameDidChangeNotification, object: textView, queue: nil) { [weak self] _ in
self?.needsDisplay = true
}
NotificationCenter.default.addObserver(forName: NSText.didChangeNotification, object: textView, queue: nil) { [weak self] _ in
self?.needsDisplay = true
}
}
public override func drawHashMarksAndLabels(in rect: NSRect) {
guard let context = NSGraphicsContext.current?.cgContext,
let textView = textView,
let textLayoutManager = textView.textLayoutManager
else {
return
}
let relativePoint = self.convert(NSZeroPoint, from: textView)
context.saveGState()
context.textMatrix = CGAffineTransform(scaleX: 1, y: isFlipped ? -1 : 1)
let attributes: [NSAttributedString.Key: Any] = [
.font: textView.font!,
.foregroundColor: NSColor.secondaryLabelColor
]
var lineNum = 1
textLayoutManager.enumerateTextLayoutFragments(from: nil, options: .ensuresLayout) { fragment in
let fragmentFrame = fragment.layoutFragmentFrame
for (subLineIdx, textLineFragment) in fragment.textLineFragments.enumerated() where subLineIdx == 0 {
let locationForFirstCharacter = textLineFragment.locationForCharacter(at: 0)
let ctline = CTLineCreateWithAttributedString(CFAttributedStringCreate(nil, "\(lineNum)" as CFString, attributes as CFDictionary))
context.textPosition = fragmentFrame.origin.applying(.init(translationX: 4, y: locationForFirstCharacter.y + relativePoint.y))
CTLineDraw(ctline, context)
}
lineNum += 1
return true
}
context.restoreGState()
}
}
I'm sure it's a bug, the TextEdit app in macOS 12.0.1 maintains selection properly for the very same RTF file. The NSAttributedString itself looks ok at first glance:
There's another interesting and unexpected (at least to me) behavior when setting the NSTextContentStorage.attributedString directly, the cursor (nor selection) is available at all and NSTextView is not editable
let docURL = Bundle.main.url(forResource: "Text", withExtension: "rtf")!
let attributedString = try! NSAttributedString(rtf: Data(contentsOf: docURL), documentAttributes: nil)
try! textContentStorage.attributedString = attributedString