Posts

Post marked as solved
15 Replies
3.8k Views
I have a document-based Cocoa MacOS Swift app, and I want to be able to Copy the document to the Pasteboard. The document is just represented by a document window: it's not text and there's nothing to 'select'. I've overridden the document's copy function, but the Copy menu item is still greyed out. I've ticked "Enabled" in the Attributes panel. How do I enable it and get the document's as its 'selected' object of operation?Thanks
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
3 Replies
510 Views
How do some apps manage to use Cut, Copy and Paste without affecting the contents of General Pasteboard? Presumably they're creating other instances of NSPasteboard using withUniqueName?If so, is it possible to find or list Pasteboard created?
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
6 Replies
1.1k Views
I've got a splitview with 3 columns, and I can adjust the position of one of the columns, but not the other one. I've no idea what I might have done to prevent this. I've tried changing the alignment things and deleting the constraints.I can delete the entire view and start again, but obviously I'd prefer not to.When the app is built, I can adjust the split to the correct size, so there's nothing preventing that. I can move the subviews themselves, or drag the entire view off, but the column just won't move.Probably something really basic, but it's driving me potty.
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
8 Replies
630 Views
I'm trying to write an app that will load MIDI files. I've written a Swfit script that works perfectly, but I'm having trouble with putting that into an app. override func read(from data: Data, ofType typeName: String) throws { let theMIDIPlayer = try AVMIDIPlayer.init(data: data, soundBankURL: nil) throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) }I'm getting a yellow warning that theMIDIPlayer was never initialized. Xcode made me put in the 'try': is that the reason? As a result, I can't use this in the ViewController, as it claims there's no such member of Document. override func viewDidAppear() { let document = self.view.window?.windowController?.document as! Document self.theView = document.theMIDIPlayer }Thanks.
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
2 Replies
504 Views
I see that NSDrawer has been deprecated. What are the alternatives? How are things like the side panels in Pages done?
Posted
by benwiggy.
Last updated
.
Post marked as solved
9 Replies
609 Views
I'm writing a MacOS app which loads PDFs as documents. I also want to save them. The app builds and works, but flags an error when I try to save or Save As. about not being able to save the file because it doesn't exist.Debug console gives the URL as something like:CGDataConsumerCreateWithFilename: failed to open `/Users/Ben/Library/Developer/Xcode/DerivedData/ReView-hitabkxsdoqaskfrelyidvcylvqs/Build/Products/Debug/file:/var/folders/qd/qjbz7jbn52938qrg166yn9l80000gn/T/TemporaryItems/(A%20Document%20Being%20Saved%20By%20ReView)/Test.pdf' for writing: No such file or directory.which looks very similar to what's described in this thread. https://forums.developer.apple.com/thread/120162My code is fairly minimal to start with: override func write(to url: URL, ofType typeName: String) throws { thePDFDocument?.write(toFile: url.absoluteString, withOptions: nil) }It was optimistic to think it would be that easy. What am I doing wrong?
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
1 Replies
662 Views
I'm trying to follow the advice in Apple's documentation for stopping an NSRunLoop:"If you want the run loop to terminate, you shouldn't use 'run'. Instead, use one of the other run methods and also check other arbitrary conditions of your own, in a loop. A simple example would be:"BOOL shouldKeepRunning = YES; /NSRunLoop *theRL = [NSRunLoop currentRunLoop];while (shouldKeepRunning && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);I'm having trouble translating that to python. It still runs forever. Noticeably, the process maxes out a core after the time interval is up.from Cocoa import NSObject, NSSpeechRecognizer, NSRunLoop, NSDefaultRunLoopMode, NSDate shouldKeepRunning = True theFuture = NSDate.alloc().initWithTimeIntervalSinceNow_(10) class Controller (NSObject): def init(self): commands = [ "up", "down" ] self.recognizer = NSSpeechRecognizer.alloc().init() self.recognizer.setCommands_(commands) self.recognizer.startListening() self.recognizer.setDelegate_(self) def speechRecognizer_didRecognizeCommand_(self, recognizer, command): shouldKeepRunning = False return command controller = Controller.alloc().init() loop = NSRunLoop.currentRunLoop() while shouldKeepRunning and (loop.runMode_beforeDate_(NSDefaultRunLoopMode, theFuture)): passAlso I'm not convinced I can retrieve the command from out of the class. Any thoughts? Thanks.
Posted
by benwiggy.
Last updated
.
Post marked as solved
2 Replies
553 Views
I have a number of python and schell scripts which work fine in the Terminal. They process any file(s) given as arguments. I can wrap them up as Automator actions, and they work fine.But Apple's support pages say that the Script menu can run any executable -- shell scripts, python, Ruby, applications, as well as AppleScripts and Automator workflows.However, when I try to use the bare script, it doesn't get passed the currently selected files, even when run as a "Finder" script. Is it possible? Or must I use the Automator wrapper?Yes, I could use the Services menu, except that it doesn't sort the scripts alphabetically and you can't use subfolders.
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
0 Replies
495 Views
I have some python and Swift scripts that set metadata in PDF files, such as Creator, Title, Author, etc.They work in Sierra, but do not work on High Sierra. I’m presuming a bug in the API itself, given that both python and Swift produce the same result.The code does not flag an error: a new PDF file is created, but no changes to the metadata are made.The problem is with PDFDocument’s writeToFile:withOptions method. As far as I can tell, there have been no changes to the API.Furthermore, PDFs created in High Sierra from “Save As PDF” (cgpdftopdf) produce syntax errors in Acrobat and GhostScript.Acrobat reports “Incorrect value type for this key” when the “Report PDF Syntax Issues” preflight analysis is run.GhostScript reports:This file had errors that were repaired or ignored.The file was produced by: Mac OS X 10.13.2 Quartz PDFContextHas anyone else observed this?Thanks(PS. This post has sat waiting for "moderation" for over a week, because apparently the forum software didn't like repeated use of greater than signs and/or asterisks.)
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
0 Replies
513 Views
I have some python and Swift scripts that set metadata in PDF files, such as Creator, Title, Author, etc.They work in Sierra, but do not work on High Sierra. I’m presuming a bug in the API itself, given that both python and Swift produce the same result.The code does not flag an error: a new PDF file is created, but no changes to the metadata are made.The problem is with PDFDocument’s writeToFile:withOptions method. As far as I can tell, there have been no changes to the API.Furthermore, PDFs created in High Sierra from “Save As PDF” (cgpdftopdf) produce syntax errors in Acrobat and GhostScript.Acrobat reports “Incorrect value type for this key” when the “Report PDF Syntax Issues” preflight analysis is run.GhostScript reports:**** Warning: considering '0000000000 XXXXX n' as a free entry. **** This file had errors that were repaired or ignored. **** The file was produced by: **** >>>> Mac OS X 10.13.2 Quartz PDFContext <<<<Has anyone else observed this?Thanks
Posted
by benwiggy.
Last updated
.
Post marked as solved
5 Replies
815 Views
Can anyone talk me through the concepts of image Property Dictionaries? I want to save a TIFF file that has a TIFF Dictionary with some keys.I'm working in python, but any advice would be welcome.My current code is:options = { kCGImagePropertyTIFFDictionary: 'TIFFDictionary', kCGImagePropertyTIFFXResolution: "300", kCGImagePropertyTIFFYResolution: "300", kCGImagePropertyTIFFResolutionUnit: 2 } CGImageDestinationAddImage(destination, image, options)But they don't get saved to the TIFF file. I don't understand where and how I need to use kCGImagePropertyTIFFDictionary.https://developer.apple.com/documentation/imageio/cgimageproperties/format_specific_dictionaries From the documentation it looks like the keys need to be inside kCGImagePropertyTIFFDictionary somehow.
Posted
by benwiggy.
Last updated
.