Post not yet marked as solved
I am seeking for this User Interface(UI) effect --> "Spotlight" a specific IBOutlet (Please see attached Image2.png below) for a week!
Explain the "Spotlight" effect : I wish to create is effect similar to NSAlert or beginSheet effect which user cannot click or access the entire window/view until user trigger a button and it back to normal. The whole window/view will becoming darken or gray EXCEPT a specific button I allow my user to interact with.
Yet, I found that there is no any trick to create such effect neither in XIB file nor objective-c code.
This is urgent for me. Eagerly waiting for your reply. Much Appreciated.
(Image 1.png)
(Image 2.png)
Post marked as Apple Recommended
As someone who learned to program on Mac OS 7.5.5, I don't mind the return of Clarus the dogcow! However others on my team are wondering if there will be a way for our app to still use the system Page Setup dialog, but not display Clarus (basically retain the appearance of Monterey's Page Setup).
Anyone know what the plan is for Clarus in the official Ventura release? Will it be possible to hide the dogcow, or substitute a different preview graphic?
Post not yet marked as solved
I have created my first app with python using py2app and it build my app successfully but when I try to open it, it crash but when I open it's package and run it from this path: myapp.app/contents/macos/myapp
it open console and run my app correctly without any error.
I can't understand how to read this kind of mac errors. I will be happy if you can help me with that:
Error Text
Post not yet marked as solved
Hello,
I‘m trying to create an app with one NSPopUpButton and two NSTextFields.
The first control is the NSPopUpButton and I want to make it the initialFirstResponder. When the app starts, it always skips the popUpButton and the focus is on the first textField. I already tried to subclass the popUpButton and to override canBecomeKeyView.
Maybe someone has a hint. Thanks.
Post not yet marked as solved
Below is a custom view class:
class MyView: NSView {
var xloc = 0.0
var yloc = 0.0
var width = 400.0
var height = 200.0
var myRect = NSRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0)
...
override func draw(_ dirtyRect: NSRect) {
let myColor = NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: self.alpha)
myColor.setFill()
dirtyRect.fill()
self.myRect = NSRect(x: self.xloc, y: self.yloc, width: self.width, height: self.height)
self.setNeedsDisplay(myRect)
self.myRect.fill(using: NSCompositingOperation.clear)
}
The view controller has a keyDown handler as follows:
override func viewDidLoad() {
super.viewDidLoad()
view.window?.backgroundColor = NSColor.white
NSEvent.addLocalMonitorForEvents(matching: .keyDown) {
self.keyDown(with: $0)
return $0
}
}
override func keyDown(with event: NSEvent) {
let theView = self.view as! MyView
if event.keyCode == 126 {
NSLog("Increasing Y coordinate")
theView.yloc = theView.yloc + 10
self.view.display()
}
}
Below is the AppDelegate.swift's content:
func applicationDidFinishLaunching(_ aNotification: Notification) {
let window = NSApplication.shared.windows.first
window?.isOpaque = false
window?.backgroundColor = NSColor.clear
window?.ignoresMouseEvents = true
window?.toggleFullScreen(self)
window?.collectionBehavior = NSWindow.CollectionBehavior.fullScreenPrimary
let screenFrame = NSScreen.main?.frame
window?.setFrame(screenFrame!, display: true)
let myView = MyView()
window?.contentView = myView
}
The rectangular hole is seen on the screen initially
The above handler is called whenever I press the up arrow key. The self.view.display() in turn calls the draw() method on the view. But the NSRect is not drawn in the new position. Request you to please help me with this. The expected result is to move (or rather redraw) the NSRect based on the keyboard up arrow click
Currently incomplete code is at: https://github.com/suchindrac/hide_pane_mac
Post not yet marked as solved
When I hover the mouse over the NSTextAttachment image inside the UITextview, it should show this option to MarkUp. All native app including Notes, TextEditor, Mail have this behaviour:
I think, by default, NSTextView will show the NSSharingServicePicker button when you hover over an image inside the text view. That’s true even for custom image-based NSTextAttachments in the attributed string.
But it is not showing the button for UITextview in MacCatalyst. Also NSSharingService class is limited to MacOS only.
Are there any alternative way to achieve this in MacCatalyst?
Post not yet marked as solved
What is the Objective C equivalent of the command line
diskutil unmount force
?
I've completed a simple app that plays 3D video. Now, I'm trying to make it open files from the menu, as well as using the Cmd-O keyboard shortcut.
But the "Open" menu item in the "File" menu is gray - I don't know exactly what this means, but it seems that the current form of the app doesn't support openning files.
I've had a func application(_ application: NSApplication, openFile filename: String) -> Bool function in my app delegate, I've had a CFBundleDocumentTypes with an entry of the MIME type of "video/mp4".
What am I doing wrong?
Post not yet marked as solved
I have a DLP-Link 3D projector which I'd like to make use of by means of a hand-made player.
So far in my project: A class MovieView : NSView within a NSWindow, with stub drawing codes.
I know that, if I place drawing codes in the func draw(...) function, then NSGraphicsContext.current will be set up for me to use. But I'm drawing from a high-priority thread (the DisplayLink), so I obviously have to set it up myself.
How should I do that in Swift?
Post not yet marked as solved
I was able to implement drag and drop with NSTableViewDiffableDataSource by subclassing and adding the missing methods. It works but the draggingSession willBeginAt method is never called so I can't provided a custom preview to the dragging. Any tips from AppKit developers or Apple engineers?
class ListCoordinator: NSTableViewDiffableDataSource<String, Int>, NSTableViewDelegate {
@objc func tableView(_ tableView: NSTableView, pasteboardWriterForRow row: Int) -> NSPasteboardWriting? {
return NSPasteboardItem(pasteboardPropertyList: row.formatted(), ofType: .string)
}
@objc func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
return .move
}
@objc func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {
...
return true
}
@objc func tableView(_ tableView: NSTableView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forRowIndexes rowIndexes: IndexSet) {
// NEVER CALLED
}
}
Post not yet marked as solved
I'm getting some Crash Reports for an app of mine that's on the Mac App Store. A few details:
-All the crash reports are on ARM-64 Macs.
-The call stack shows my app calling NSURL's -getResourceValue:forKey: method with NSURLLocalizedNameKey, which is the last call made by my app before the crash. After that crash logs look like this:
**Thread 0 Crashed:
0 libobjc.A.dylib 0x00000001a623c4b0 objc_retain + 16
1 LaunchServices 0x00000001a6954f68 -[FSNode(PathAndName) nameWithError:] + 72
2 LaunchServices 0x00000001a6a36278 +[_LSDisplayNameConstructor(ConstructForAnyFile) displayNameConstructorWithContextIfNeeded:bundle:bundleClass:node:preferredLocalizations:error:] + 2732
3 LaunchServices 0x00000001a6a357ac +[_LSDisplayNameConstructor(ConstructForAnyFile) displayNameConstructorWithContextIfNeeded:node:error:] + 44
4 LaunchServices 0x00000001a6ae5b20 LaunchServices::URLPropertyProvider::getDisplayNameConstructor(LaunchServices::Database::Context&, FSNode*, LaunchServices::URLPropertyProvider::State*, NSError* __autoreleasing*) + 88
5 LaunchServices 0x00000001a6ae1930 LaunchServices::URLPropertyProvider::prepareLocalizedNameValue(LaunchServices::Database::Context&, FSNode*, __FileCache*, __CFString const*, LaunchServices::URLPropertyProvider::State*, NSError* __autoreleasing*) + 328
6 LaunchServices 0x00000001a6953d6c LaunchServices::URLPropertyProvider::prepareValues(__CFURL const*, __FileCache*, __CFString const* const*, void const**, long, void const*, __CFError**) + 456
7 CoreServicesInternal 0x00000001a8def6f0 prepareValuesForBitmap(__CFURL const*, __FileCache*, _FilePropertyBitmap*, __CFError**) + 452
8 CoreServicesInternal 0x00000001a8dec5ec _FSURLCopyResourcePropertyForKeyInternal(__CFURL const*, __CFString const*, void*, void*, __CFError**, unsigned char) + 236
9 CoreFoundation 0x00000001a64546b0 CFURLCopyResourcePropertyForKey + 144
10 CoreFoundation 0x00000001a646b944 -[NSURL getResourceValue:forKey:error:] + 120**
--
I haven't been able to reproduce the issue on my ARM-64 Mac. Not sure what's going with _LSDisplayNameConstructor or if there is a way I can workaround/resolve.
Some of the crashes have the following lines included:
Kernel Triage:
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
Post not yet marked as solved
When I tried this, the app crashed immediately with a requirement to use NSTextContentStorage subclass
Post not yet marked as solved
I recently updated my sandboxed application to the MacOS 12 target. Among deprecation, there is the allowedFileTypes method for NSOpenPanel/NSSavePanel, replaced with allowedContentTypes. I updated my document opening and importing methods to reflect this change. For example, to import a CSV or JSON file, I coded:
myPanel.allowedContentTypes = [NSArray arrayWithObjects:UTTypeJSON, UTTypeCommaSeparatedText, UTTypeTabSeparatedText, [UTType typeWithIdentifier: @"org.openxmlformats.spreadsheetml.sheet"], nil] ;
All these UTTypes are described in the "Imported Type UTIs" section of the app's Info.plist.
Unfortunately, it is impossible to select any of Json, Csv or Xlsx file in the NSOpenPanel since I made these changes to be in line with MacOS12 requirements. Worse, I cannot open my own file format with its own UTI (described in Info.plist too)! The only way to open/import is to set myPanel.allowOtherFileTypes to TRUE, and to remove any code referring to allowedContentTypes.
What is quite strange is that exporting works correctly after updating. My spotlight plugin works also (for my file format)… Something I missed? Help welcome as my app became useless since I made these changes, and I use it every day for my work (and improving it before launching it on the Appstore)
Post not yet marked as solved
Looking for a Cocoa example/tutorial in Objective C, on how to create a 400x90 pixel panel with outlets for a progress bar, textfield and a button (stop) to display temporarily while images are loading.
I've added a WindowController + xib to the app's main storyboard but don't know how to use it to access the outlets in the progress panel.
Post not yet marked as solved
Hi,
I'm working on making a Document based app for MacOS using AppKit and I wanted the different documents to be displayed as tabs of the same window which after a lot of research I managed to do using this single line:
windowController.window?.tabbingMode = .preferred
which I added inside the makeWindowControllers function of my Document.
I figured that in order to be able to style my tabs I should use this method:
windowController.window?.tab.attributedTitle = ...
But whatever I added after this = didn't do anything to my tabs.
For example I tried this:
windowController.window?.tab.attributedTitle = NSAttributedString(string: "Hello", attributes: [NSAttributedString.Key.backgroundColor: NSColor.red])
Weirdly, using this method:
windowController.window?.tab.title = ...
did work but is far more limited than the other one.
Maybe I did something wrong in my implementation of the tabs but it seems to work properly when I run it, only the colors and fonts don't match what I'd like to make which is why I wanted to change them using the attributed title.
Here's my full code for the function:
override func makeWindowControllers() {
let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil)
if let windowController =
storyboard.instantiateController(
withIdentifier: NSStoryboard.SceneIdentifier("Document Window Controller")) as? NSWindowController {
addWindowController(windowController)
windowController.window?.tabbingMode = .preferred
windowController.window?.tab.attributedTitle = NSAttributedString(string: "hey", attributes: [NSAttributedString.Key.backgroundColor: NSColor.red])
// Set the view controller's represented object as your document.
if let contentVC = windowController.contentViewController as? ViewController {
contentVC.representedObject = content
contentViewController = contentVC
}
}
}
I would really appreciate some help on this issue!
Thanks by advance,
Cyprien
Post not yet marked as solved
I created a custom keyboard layout with the app Ukelele, based on a built-in layout and thus using the original icon.
However, the icon is not loaded as a template image in the Menu Bar. The result is that when a darker background image is used (or a dynamic background turns darker), the black part of the icon does not switch to white and all I see is a black square with the letters of the keyboard layout not readable:
This was fine until 12.3 when flags were used as icons instead.
Is this a bug and is there a way to workaround this?
Post not yet marked as solved
I have an Objective-C macOS app which provides a service that provides unique services on selected text.
This app has been for sale in the Mac App Store for several years.
The app registers as service provider during 'appDidFinishLaunching' with: [[NSApplication sharedApplication] setServicesProvider:self];
When my service is invoked it uses the standard service method:
(void)serviceName:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error
In the body of this standard service method the contents of the NSPasteboard (pboard) are examined and consumed by my app.
- (void) kudosService:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error; {
if ([pboard pasteboardItems].count==0) { return; }
NSPasteboardItem *pI = [pboard pasteboardItems][0];
NSLog(@"pI:%@",pI.types );
for (NSString *uti in pI.types) {
NSLog(@"uti:%@ string:%@",uti, [pI stringForType:uti] );
}
...
}
Something has changed with Preview app; at this point I'm inclined to think the change occurred with version 11.
Console output for Preview
pI:(
"public.utf8-plain-text",
"public.rtf",
"public.utf16-external-plain-text"
)
uti:public.utf8-plain-text string:(null)
uti:public.rtf string:(null)
uti:public.utf16-external-plain-text string:(null)
This is the output regardless of whether or not the user has a mere text selection OR has formally 'Cop(ied)' [Cmd-C] the text in the Preview window!
Please NOTE if I open the exact same .pdf document in Safari and invoke the service from Safari I see the expected Console output:
pI:(
"public.utf8-plain-text"
)
uti:public.utf8-plain-text string:The Best Gluten-Free Chocolate Cake
When did this change in Preview behavior occur?
Can anyone point me to some documentation, which I have obviously overlooked, that would shed some light on this matter!
Post not yet marked as solved
Is there a simple way to create an NSFontCollection based on NSFontDescriptor querying to gather all installed/available fonts with a MATH table? It doesn't look like there's an attribute for that, but I don't know how else to search other than correlating with features like ssty, dtls, and flac.
Post not yet marked as solved
I would like to be able to get either the key code or the characters/text from an NSEvent/KeyEvent. Absolutely no idea how to do this as the documentation I have found so far has been very limited. I believe I need to create an instance of NSEvent but I do not know how.
My script is below. I am working on a speedrun macro for Minecraft.
This script is fully functioning as is, but currently all it does is check if the control key has been pressed via checking the modifier flags of NSEvent.
use framework "AppKit"
use scripting additions
global ca
set ca to current application
# you may change the following variables
global seed
set seed to "8398967436125155523"
# do not change anything below this line
to isModifierPressed(modifier)
((ca's NSEvent's modifierFlags()) / modifier as integer) mod 2 is equal to 1
end isModifierPressed
repeat
if isModifierPressed(ca's NSEventModifierFlagControl) then execute()
delay 0.01
end repeat
on execute()
tell application "System Events"
delay 0.1
keystroke tab
delay 0.02
keystroke return
delay 0.02
repeat 3 times
keystroke tab
delay 0.02
end repeat
keystroke return
delay 0.02
repeat 2 times
keystroke tab
delay 0.02
end repeat
repeat 3 times
keystroke return
delay 0.02
end repeat
repeat 4 times
keystroke tab
delay 0.02
end repeat
keystroke return
delay 0.02
repeat 3 times
keystroke tab
delay 0.02
end repeat
keystroke seed
delay 0.02
repeat 6 times
keystroke tab
delay 0.02
end repeat
keystroke return
end tell
end execute
We want to have a login window stay in front and key, until the user signs in. We want it to stay in front even if switching away from it. Now, this does seem possible, since zoom just did it to me while I was getting into a call to discuss this, but I can't figure out how.
In this particular case, I am instantiating an NSViewController subclass, and then creating an NSWindow for it to use. I have tried setting the NSWindow.level to all sorts of values, and they don't seem to work.
help?