Keynote Application crashes / dies after setting properties on new document
Hi there, it sounds like a very specific problem and I also can't tell if it's not even due to the Keynote app itself.
When I run the sample code below, the keynote app dies about 20 seconds after I set properties of a new document. With pure AppleScript I could not observe this problem.
Could this have something to do with PyXA or the PyObjC framework used in relation to the garbage collection algorhythm?
# -*- coding: utf-8 -*-
import PyXA
import time
keynote = PyXA.Application('Keynote')
keynote.activate()
newDocumentName = 'Untitled'
wrongDocument = keynote.new_document(newDocumentName)
# If a document was already open, not the newly created document is returned
# here, but the previously existing document. Keynote seems to re-sort the
# list with the creation of documents.
newDocument = keynote.documents()[0]
# setting the properties of the newly created document crashes keynote in
# about 20 seconds...
newDocument.width = 2224
newDocument.height = 1668
time.sleep(20)
# by now, the keynote app should have crashed / died by accident.
# so the next statement should fail...
currentDocument = keynote.documents()[0]
pass
Hi @benkfra, this appears to be because you're only providing the file name, not a full path. If you change Untitled to something along the lines of /Users/benkfra/Documents/Untitled.key, you shouldn't see this issue. I can add an error for when no full path is provided to clarify this.
If a document was already open, not the newly created document is returned
I'll fix this for the next release 🙂