Wednesday, November 20, 2019

#1 2018-10-11 04:01:53 am

vw-as
Member
Registered: 2015-08-25
Posts: 7

Pages - get ID or names of templates

I am new to AppleScript and at a very early stage of learning. Using macOS 10.13.6, Pages 7.2

At https://iworkautomation.com/pages/template.html the example scripts to do not work (they all compile without error messages), specifically:

Applescript:

tell application "Pages"
   set the templateIDs to the id of every template
end tell

Resulting in the following error message:

error "Pages got an error: Can’t get every template." number -1728 from every template



While the other example:

Applescript:

tell application "Pages"
   get the name of every template
end tell

generates the following error message:

Pages got an error: Can’t get every template.



Similarly with one of the examples in the dictionary for template:

Applescript:

tell application "Pages"
   make new document with properties {document template:template "Essay"}
end tell

leads to

Pages got an error: Can’t make class document.



Any help would be gratefully received.


Filed under: pages

Offline

 

#2 2018-10-11 05:39:21 am

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

Re: Pages - get ID or names of templates

With the same settings, running

Applescript:

tell application "Pages"
   name of every template
end tell

returned :
{"Vierge", "Vierge - Paysage", "Prise de notes", "Reportage", "Dissertation", "Rapport scolaire", "Exposé", "Publication de recherche", "Rapport moderne", "Proposition de projet", "Livre vierge", "Standard", "Manuel", "Roman", "Livre vierge", "Standard", "Reportage", "Conte", "Leçon", "Manuel", "AFNOR", "Lettre classique", "Lettre moderne", "Lettre professionnelle", "Lettre traditionnelle", "Lettre avec photo", "Lettre élégante", "Lettre en gras", "Lettre informelle", "Curriculum Vitae", "CV classique", "CV moderne", "CV professionnel", "CV élégant", "CV en gras", "CV informel", "À louer", "À vendre", "Prospectus à tabulations", "Immobilier", "Perdu/Trouvé", "Petite affiche", "Grande affiche", "Petite affiche pour un événement", "Grande affiche pour un événement", "Petite affiche pour une fête", "Grande affiche pour une fête", "Petite affiche scolaire", "Grande affiche scolaire", "Petite affiche d’imprimerie", "Grande affiche d’imprimerie", "Bulletin", "Bulletin d’infos du journal", "Bulletin simple", "Bulletin Serif", "Journal de l’école", "Carte avec photo verticale", "Carte avec photo horizontale", "Carte d’anniversaire", "Carte postale Immobilier", "Carte postale de l’événement", "Carte postale de déménagement", "Enveloppe classique", "Enveloppe moderne", "Enveloppe professionnelle", "Enveloppe élégante", "Enveloppe en gras", "Enveloppe informelle", "Cartes de visite classiques", "Cartes de visite modernes", "Cartes de visite", "Cartes de visite élégantes", "Cartes de visite en gras", "Cartes de visite informelles", "Diplôme", "Certificat pour enfants", "Facture", "Dépliant élégant", "Dépliant - Musée"}


I assumed that you got what you described because the app wasn't open when you called the script but here it made no change.

Using the name of a template existing in French I ran :

Applescript:

tell application "Pages"
   make new document with properties {document template:template "Dissertation"}
end tell

And got the wanted new document :
document id "46216FB9-4B47-4D06-B0DF-9E46B14C5F0E" of application "Pages"


If I run :

Applescript:

tell application "Pages"
   set the templateIDs to the id of every template
end tell

I get :
{"Application/Blank/ISO", "Application/BlankLandscape/ISO", "Application/00_Note-taking/ISO", "Application/04_Essay/ISO", "Application/04_Term_Paper/ISO", "Application/09_School_Report/ISO", "Application/06_Visual_Report/ISO", "Application/00_ResearchPaper/ISO", "Application/01_Modern_Report/ISO", "Application/02_Modern_Business_Project_Proposal/ISO", "Application/00B_Blank_Portrait/ISO", "Application/08B_Basic_Portrait/ISO", "Application/00C_Textbook_Portrait/ISO", "Application/11B_Novel_Portrait/ISO", "Application/00B_Blank_Landscape/ISO", "Application/07B_Basic_Landscape/ISO", "Application/02B_Report_Landscape/ISO", "Application/13_StoryBook/ISO", "Application/06B_Lesson/ISO", "Application/00D_Textbook_Landscape/ISO", "Application/03_French_Modern_Business_AFNOR/ISO", "Application/05_NewClassic-Letter/ISO", "Application/03_Theme_Letter/ISO", "Application/02_Modern_Business-Letter/ISO", "Application/03_Theme_Letter_Traditional/ISO", "Application/06_New_Photo/ISO", "Application/05_NewElegant-Letter/ISO", "Application/01_BoldType_Letter/ISO", "Application/01_Modern_Fun-Letter/ISO", "Application/03_Modern_Business-CV/ISO", "Application/05_NewClassic-Resume/ISO", "Application/03_Theme_Resume/ISO", "Application/02_Modern_Business-Resume/ISO", "Application/05_NewElegant-Resume/ISO", "Application/01_BoldType_Resume/ISO", "Application/01_Modern_Fun-Resume/ISO", "Application/10_For_Rent/ISO", "Application/07_For_Sale_Scooter/ISO", "Application/10_For_Sale_Bicycle/ISO", "Application/04_Real_Estate_Flyer/ISO", "Application/10_Found_Flyer/ISO", "Application/10_Photo_Poster-Letter_size/ISO", "Application/10_Photo_Poster-Tabloid_size/ISO", "Application/01_Event_Poster-Letter_size/ISO", "Application/01_Event_Poster-Tabloid_size/ISO", "Application/06_Party_Poster-Letter_size/ISO", "Application/06_Party_Poster-Tabloid_size/ISO", "Application/06_School_Event_Poster-Letter_size/ISO", "Application/06_School_Event_Poster-Tabloid_size/ISO", "Application/01_Typographic_Poster-Letter_size/ISO", "Application/01_Typographic_Poster-Tabloid_size/ISO", "Application/08_Classic_Informal_Newsletter/ISO", "Application/08_Journal_Newsletter/ISO", "Application/01_Simple_Newsletter_Sans/ISO", "Application/07_Simple_Newsletter_Serif/ISO", "Application/12_School_Newsletter/ISO", "Application/06_Photo_Card-Vertical/ISO", "Application/08_Photo_Card-Horizontal/ISO", "Application/06_Birthday_Card/ISO", "Application/04_Real_Estate_Postcard/ISO", "Application/01_Gallery_Card/ISO", "Application/10_Moving_Card/ISO", "Application/05_NewClassic-Envelope/ISO", "Application/03_Theme_Envelope/ISO", "Application/02_Modern_Business-Envelope/ISO", "Application/05_NewElegant-Envelope/ISO", "Application/01_BoldType_Envelope/ISO", "Application/01_Modern_Fun-Envelope/ISO", "Application/05_NewClassic-BusinessCard/ISO", "Application/03_Theme_BusinessCard/ISO", "Application/02_Modern_Business-BusinessCard/ISO", "Application/05_NewElegant-BusinessCard/ISO", "Application/01_BoldType_Business_Card/ISO", "Application/01_Modern_Fun-BusinessCard/ISO", "Application/04_Classic_Certificate/ISO", "Application/11_Kids_Certificate/ISO", "Application/02_Modern_Invoice/ISO", "Application/05_Elegant_Brochure-New/ISO", "Application/01_Museum_Brochure/ISO"}

As you may see, in this case the embedded names aren't localized as they are when we ask for names.


Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 11 octobre 2018 13:38:26

Last edited by Yvan Koenig (2018-10-11 11:49:41 am)

Offline

 

#3 2018-10-13 02:40:31 am

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

Re: Pages - get ID or names of templates

Hi. Welcome to MacScripter.

Your script snippets work fine for me too. It sounds as if either something's gone wrong with the installation of Pages on your machine or there's some incompatability between Pages 7.2 and macOS 10.13.6 — although App Store wouldn't have offered it to you for download if there was. Are you able to open documents from templates manually within Pages?

I can reproduce your errors on my Mojave machine if I have Pages 4.3 open at the same time or instead. It has slightly different scripting commands from Pages 7.2 (and can't open new or existing documents in Mojave anyway.)


NG

Offline

 

#4 2018-10-13 09:29:11 am

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

Re: Pages - get ID or names of templates

Hello Nigel

I made my tests with 10.13.6 and Pages 7.2. Everything worked flawlessly.

Bad news, I read in a forum that the update to 7.2 is proposed on machines running 10.12.x but that the updated application fails when asked to run.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 13 octobre 2018 17:29:04

Offline

 

#5 2018-10-13 04:36:02 pm

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

Re: Pages - get ID or names of templates

Hi Yvan.

Interesting…!  hmm


NG

Offline

 

#6 2018-10-15 02:30:40 am

vw-as
Member
Registered: 2015-08-25
Posts: 7

Re: Pages - get ID or names of templates

Thank you for all of the responses.

The problem was with Pages - although I do not know exactly what the problem is/was.

Once I quitted Pages and launched it again - all of the scripts ran without issue.


Filed under: pages

Offline

 

#7 2019-10-22 06:21:46 am

flexxx
Member
Registered: 2019-07-22
Posts: 4

Re: Pages - get ID or names of templates

Hi there, I basically ran into the same problem.
I'm running a sandboxed MacOS App which has all the correct permissions granted.

For some reason in the script

Applescript:

every template

can not be read/accessed.

I tried to put in a delay to be sure the app is launched and also started it before running my command.

Additionally I used ScriptDebugger to invoke just the following script:

Applescript:

tell application "Pages"
   get the name of every template
end tell

which worked the first time I invoked it, but failed every time after that.

I can get an AEPrint from ScriptDebugger which contains the following:

'obj '{
    'form':'indx',
    'want':'tmpl',
    'seld':'abso'($206C6C61$),
    'from':[
        0x0,
        7c07c "Pages"
    ]
}

and the "pretty printed error message" is "Invalid object reference".

So it seems that Pages can not resolve the command/object "every template".

The behaviour seems somewhat inconsistent. Most of the times it will not work, but some rare times it actually will work. But I was not yet able to figure out the cause of that. It doesn't clearly look like its timing related. Quitting and rerunning Pages did not help, as well as restarting the mac.

Anybody has any suggestions? Thanks!


Filed under: template, Error, pages

Offline

 

#8 2019-10-22 06:37:11 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6037

Re: Pages - get ID or names of templates

flexxx wrote:

I'm running a sandboxed MacOS App which has all the correct permissions granted.



Are you saying you're running the script from a sandboxed app?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#9 2019-10-22 07:10:14 am

flexxx
Member
Registered: 2019-07-22
Posts: 4

Re: Pages - get ID or names of templates

Shane Stanley wrote:
flexxx wrote:

I'm running a sandboxed MacOS App which has all the correct permissions granted.



Are you saying you're running the script from a sandboxed app?



Yes, but I also run it via the "Script Debugger" App.

What confuses me is that it was working in the past and it is also sometimes working now. But most times it isn't for whatever reason.

Offline

 

#10 2019-10-22 07:41:38 am

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

Re: Pages - get ID or names of templates

Yvan Koenig wrote:

Hello Nigel

I made my tests with 10.13.6 and Pages 7.2. Everything worked flawlessly.

Bad news, I read in a forum that the update to 7.2 is proposed on machines running 10.12.x but that the updated application fails when asked to run.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 13 octobre 2018 17:29:04




I forgot this old message.
The problem was solved and at this time,10.13.6 support Keynote v9.1 , Numbers v6.1 , Pages v8.1.
Newer versions require Mojave or higher.

With Pages v8.1 under 10.13.6 the script grabbing the names of templates behave flawlessly.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 22 octobre 2019  15:41:33

Offline

 

#11 2019-10-22 07:44:49 am

flexxx
Member
Registered: 2019-07-22
Posts: 4

Re: Pages - get ID or names of templates

Thanks for the info.
I'm running Pages 8.2 on 10.15 Catalina, maybe it's a problem with Pages 8.2 ?

Offline

 

#12 2019-10-23 03:13:07 am

flexxx
Member
Registered: 2019-07-22
Posts: 4

Re: Pages - get ID or names of templates

For whatever reason it started working again yesterday and still continues to work.
And I haven't heard from users that they have that problem, so there might be a chance that it has to do with the configuration of my machine.

Thank you!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)