Posts

Post marked as solved
362 Views

Get URL of loaded document?

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?
Asked
by benwiggy.
Last updated
.
Post not yet marked as solved
504 Views

NSRunLoop in python

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.
Asked
by benwiggy.
Last updated
.
Post marked as solved
448 Views

Send arguments to script menu scripts?

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.
Asked
by benwiggy.
Last updated
.
Post not yet marked as solved
379 Views

Bugs in PDFKit API?

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.)
Asked
by benwiggy.
Last updated
.
Post not yet marked as solved
430 Views

Problems with PDF creation and metadata in High Sierra

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
Asked
by benwiggy.
Last updated
.
Post marked as solved
703 Views

Problem with image property dictionaries

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.
Asked
by benwiggy.
Last updated
.
Post marked as solved
782 Views

How to open a window with filepath given

I'm trying to do the fairly ordinary task of getting a file from NSOpenPanel (from File > Open) and then create a window, passing the filepath to the window so that it can run an AVPlayer. My AppDelegate is:@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @IBAction func browseFile(sender: AnyObject) { let dialog = NSOpenPanel(); if (dialog.runModal() == NSModalResponseOK) { let result = dialog.url if (result != nil) { // Pass the URL to the ViewController } else { return } } }My ViewController is:class ViewController: NSViewController { @IBOutlet weak var playerView: AVPlayerView! override func viewDidLoad() { super.viewDidLoad() // Get the URL somehow let player = AVPlayer(url: url) playerView.player = player }How do I join the two? Ideally, in such as way that I can create multiple windows.Am I missing some source of basic templates for these kind of very basic operations?
Asked
by benwiggy.
Last updated
.
Post not yet marked as solved
514 Views

recommend literature?

Can anyone point me in the direction of some good literature about making applications with Xcode?I just don't get all the delegates and controllers and views and actions and outlets and what-have-you. I've looked at various websites, including Apple's pages, and sat through far too many low-fact-density Youtube videos, but I really need to find a decent text-based explanation. Where did you find the best info?Thanks
Asked
by benwiggy.
Last updated
.
Post not yet marked as solved
2.4k Views

Which scripting language?

I'm looking at the various language options for scripting in OS X, and wondering if anyone can offer any advice.1. PythonI've tried python, and the PyObjC cocoa bridge works reasonably well. However, the bundled version of PyObjC in OS X is incomplete, ancient and unsupported. I could install the newer versions of python and PyObjC, but I prefer something that works out of the box on any Mac.2. SwiftAgain, I've had some success here, and written a few little scripts which work well. The only down-side is that Swift still seems to be a moving target, and things need rewriting every time the version gets updated.3. RubyRubyCocoa seems to be installed on OS X by default, though I can't find out much documentation about it. But it's the most compelling candidate so far.4. AppleScript.Just No. It's Englishy-ness and lack of algebraic rigour I find awful and confusing.Have I missed anything?
Asked
by benwiggy.
Last updated
.
Post marked as solved
743 Views

Link controller items to AppDelegate?

This is really basic: I've got an IBOutlet in ViewController, but when I use it in AppDelegate, Xcode says "Use of unresolved identifier".What else do I need to do?
Asked
by benwiggy.
Last updated
.
Post not yet marked as solved
439 Views

How to get duration from AVMIDIPlayer

AVMIDIPlayer has an instance property "duration":var duration: TimeInterval { get }So I've written:let time = midiPlayer?.duration as! TimeInterval print (time)which runs, but of course I get error messages about 'forced cast from 'TimeInterval?' to 'TimeInterval' (aka 'Double') only unwraps optionals; did you mean to use '!'?What am I doing wrong? (It's usually not enough or too many question marks....😁 )
Asked
by benwiggy.
Last updated
.
Post not yet marked as solved
258 Views

swift future versions?

I've been trying to learn Swift, and much of the code examples and information I've found relates to Swift 2, and doesn't work with Swift 3 without modification.Several Xcode projects retain fatal errors when Xcode tries to update the Swift code, too.My question is, are we likely to see this process being repeated regularly, with Swift 4.0 and 5 and 6...?If so, that's a major turn-off for using the language. I don't really want to check and modify all my code every year.
Asked
by benwiggy.
Last updated
.
Post not yet marked as solved
494 Views

apple sample python code doesn't work?

Apple publishes a whole load of open source code examples. There's a PDF parser in python which exists in a couple of slightly different versions. However, none of them work.They all produce a variety of syntax errors or crash the python process!https://opensource.apple.com/source/pyobjc/pyobjc-49/pyobjc/pyobjc-framework-Quartz-2.5.1/Examples/Programming%20with%20Quartz/ParsePageContents/parse_page_contents.py.auto.htmlHere's another, with a few differences:https://opensource.apple.com/source/pyobjc/pyobjc-14.1.1/pyobjc/stable/pyobjc-framework-Quartz/Examples/Programming%20with%20Quartz/ParsePageContents/parse_page_contents.pyAny idea how I tell which is the most up-to-date version? Should I report this to bugreporter?
Asked
by benwiggy.
Last updated
.