Monday, December 17, 2018

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

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

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: 3293

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: 4741

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: 3293

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: 4741

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: 3

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

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)