Sunday, September 22, 2019

#1 2019-04-22 07:28:01 am

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 34

Pages temp doc will not delete

Thanks for looking at this for me. I failed to fix this last year and now it's come back to haunt me
My script is meant to generate a number of PDF docs by creating from a pages template, substituting images and text into placeholders, exporting the doc to PDF, saving a local pages copy, repeated x times

Using an applescript
I create a new pages doc from a template.
a document - "untitled.pages" appears.
the script then adds images to placeholders in the doc.
export a pdf copy of the now modified pages document with it's own filename - works fine every time
save the original "untitled.pages" document with a new file name - works fine every time

I then tell pages "close every document without saving"

when i close pages i get the dialog box asking me if i want to save "untitled.pages" and the script hangs waiting for a decision.
or if I quit pages, when I open it again, "untitled.pages" appears with a dialogue box as above.

I need to know how to close/delete "untitled.pages" OR how to save and then close it.

here is the relevant snippet

Applescript:

tell application "Pages"
           tell thisDocument
               set thisPlaceHolderImage to image 1 -- gets placeholder location in pages template
               set file name of thisPlaceHolderImage to (path to desktop folder as text) & pdfFileName as alias
               export thisDocument to file bpassDoc as PDF -- this makes and saves the output file
               save thisDocument in file bpassTemp as pages
               log "Temporary pages doc closed."
           end tell
           tell application "Pages"
               close every document without saving
               log " Pages documents closed."
           end tell
       end tell

Thanks for reading this - I don't mind being shown that I am dim.....

Max

Model: iMac mid 2011
Browser: Safari 605.1.15
Operating System: macOS 10.14


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.


Filed under: placeholder

Offline

 

#2 2019-04-22 09:13:31 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3579

Re: Pages temp doc will not delete

Here, under 10.13.6, I am unable to reproduce your problem.
I just added two parentheses to the instruction:

Applescript:

set file name of thisPlaceHolderImage to ((path to desktop folder as text) & pdfFileName) as alias

The newly created document is not named "untitled.pages" but "untitled"
The extension is only added to saved documents.

I tested with:

Applescript:

set bpassDoc to (path to desktop as text) & "export.pdf"
set bpassTemp to (path to desktop as text) & "temporary.pages"
set pdfFileName to "2019-04-12 16-43.pdf" # name of a file available on the desktop

tell application "Pages"
   set untitled_Loc to localized string "Untitled" from table "Pages"
   --> "Sans titre"
   set thisDocument to document untitled_Loc
   tell thisDocument
       
       set thisPlaceHolderImage to image 1 -- gets placeholder location in pages template
       set file name of thisPlaceHolderImage to ((path to desktop folder as text) & pdfFileName) as alias
       
       export thisDocument to file bpassDoc as PDF -- this makes and saves the output file
       save thisDocument in file bpassTemp as pages
       log "Temporary pages doc closed."
       close it without saving
   end tell
   
   log (get count of documents)
   --> 0
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 22 avril 2019  17:11:29

Last edited by Yvan Koenig (2019-04-22 09:19:52 am)

Offline

 

#3 2019-04-22 11:29:05 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5013

Re: Pages temp doc will not delete

It works for me too, using Pages 8.0 in Mojave. Is the problem due to something else happening in the script?

I wouldn't double up the application and document references:

Applescript:

set bpassDoc to (path to desktop as text) & "export.pdf"
set bpassTemp to (path to desktop as text) & "temporary.pages"
set pdfFileName to "143_SM30-3-19.jpg"

tell application "Pages"
   set thisDocument to (make new document with properties {document template:template "Modern Report"})
   
   tell thisDocument
       set thisPlaceHolderImage to image 1
       set file name of thisPlaceHolderImage to ((path to desktop as text) & pdfFileName) as alias
       export to file bpassDoc as PDF -- thisDocument is the default target in this tell statement.
       save in file bpassTemp as pages -- Ditto.
       -- close without saving -- Ditto.
   end tell
   
   close every document without saving -- Already telling application "Pages"
end tell


NG

Offline

 

#4 2019-04-22 11:44:49 am

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 34

Re: Pages temp doc will not delete

Nigel, Yvan,

Thanks for answering. Both your proposals work well and carry out the main function, producing the PDF and Pages copies. The export(.PDF) and filed copy(pages) has always worked perfectly.
The focus here is the "untitled" pages window that is still open after the above two documents have been created.

The script will generate up to 120 individual 1 page .PDF files. So, when the repeat loop makes another copy of the template that becomes "Untitled 2" which will not close.
As the script progresses you will see that the pages app has dozens of unsaved "Untitled" documents in memory and cascading down the screen. This will happen even if i quit pages and when the script activates the app again, the untitled 's are still there.

Close without saving, close every document, set focus to the window and close it, quit without saving all do the same thing. I get a pages dialogue box asking Delete, Cancel, Save.

I'll review what I have been doing here and try your constructions. They are usually better than mine anyway!  I think i will build another sub script doing just this job to try to get to the bottom of this. I will report what happens

Thanks for taking the time to help.

Max


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.

Offline

 

#5 2019-04-22 12:03:46 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3579

Re: Pages temp doc will not delete

It seems that I wasn't clear enough.
Here, the document is correctly closed.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 22 avril 2019  20:03:37

Offline

 

#6 2019-04-23 03:06:34 am

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 34

Re: Pages temp doc will not delete

Dear Yvan,

I am still getting inconsistencies but may have found the problem.

I have had a number of odd events, sometimes when a new document is catered from the template , the 'new' document is "Untitled x" where x is anything from 1 to 12. This number can vary up or down. It was not just "Untitled".

By right clicking on the pages icon on the toolbar I found a list of "Untitled x" documents that I thought had been deleted. These were all unsaved and opened when selected. I deleted all these manually and changed my script to follow your advice and Nigels.

When running the script i found that this list was growing again, ALTHOUGH I could not find the documents with a search. Some would not open when selected on the toolbar icon. Then I noticed that if i left a few minutes between runs, the x number would move again....

You have probably guessed.....I pointed all the files to a non-icloud folder and am now unable to reproduce the problem.

The "Untitled x" documents are no longer being cached. The 'new' document created in each loop is always "Untitled" with no number and the list on the toolbar icon has no entries.   

I will take the time to reproduce the problem again and then run the fix. This is in order to prove what was wrong. I will report again after that in case somebody else needs to know.

Thank you for the help you (and others) offer. This was not my first time here and you have helped a lot in the past.

Max


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.

Offline

 

#7 2019-06-06 09:30:38 am

Headroom San
Member
From:: Stratford upon Avon
Registered: 2016-07-15
Posts: 34

Re: Pages temp doc will not delete

Yvan, Nigel,

I said i would respond, but forgot. The fixes both work, but only most of the time.

Every now and again there are new untitled docs being held by the Bags app.

In the end, I just wrote a cleanup script which would close pages and my script, then it would open pages and using mouse clicks delete each unsaved untitled file one after the other.

I was never able to pin down what was happening nor why it was intermittent.

Thanks as ever

Max


Beware the beast Man, for he is the Devil's pawn. Alone among God's primates, he kills for sport or lust or greed. Yea, he will murder his brother to possess his brother's land. Let him not breed in great numbers, for he will make a desert of his home and yours. Shun him; drive him back into his jungle lair, for he is the harbinger of death.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)