If the problem is to insert automatically the current date given the system settings here is a neat soluce giving to all of us a feature used by in
thebox templates.
--[SCRIPT change2oneShotTemplate]
(*
Save the script as an Application (Application Bundle if you want to use it on a MacIntel)
Store it on the Desktop.
Create a document matching your default requirements.
Insert DateTime where you want.
Double click the inserted date to adjust the format as you want.
IMPORTANT: check the box entitled "Automatically update on open"
Save your document.
Drag and drop its icon on the script icon.
You may also double click the script's icon then navigate to select the document.
The script will replace the item:
"sf:auto-update=" by the alternate one "sf:one-shot=".
This one is used by Apple in the inthebox template but there is no GUI available to allow us to insert it.
When it is set to true, "sf:auto-update=" insert the current date time but it's a live one which will change each time you will open the created standard document.
When it is set to true, "sf:one-shot=" insert the current date time but it's a fixed one which will not change when you will re-open the created standard document.
Yvan KOENIG (Vallauris, FRANCE)
18 mars 2009
*)
property permittedK4 : {"com.apple.iWork.keynote.sffkey"}
property permittedK5 : {"com.apple.iwork.keynote.key"}
property permittedKey : permittedK5 & permittedK4
(* Keynote documents are treated differently *)
property permitted4 : {"com.apple.iWork.pages.sffpages", "com.apple.iwork.numbers.sffnumbers"} & permittedK4
property permitted5 : {"com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers"} & permittedK5
property permitted : permitted5 & permitted4
property typeID : missing value
--=====
on run (*
lignes exécutées si on double clique sur l'icône du script application
• lines executed if one double click the application script's icon *)
tell application "System Events"
if my parleAnglais() then
set myPrompt to "Choose an iWork’s document"
else
set myPrompt to "Choisir un document iWork"
end if -- parleAnglais
if 5 > (system attribute "sys2") then (*
if Mac Os X 10.4.x *)
set allowed to my permitted
else (*
it's Mac OS X 10.5.x with a bug with Choose File *)
set allowed to {}
end if -- 5 > (system…
my commun(choose file with prompt myPrompt of type allowed) (* un alias *)
end tell
end run
--=====
on open (sel) (*
sel contient une liste d'alias des élémentsqu'on a déposés sur l'icône du script (la sélection)
• sel contains a list of aliases of the items dropped on the script's icon (the selection) *)
my commun(item 1 of sel) (* an alias *)
end open
--=====
on commun(thePack) (*
• thePack is an alias *)
local pFold, pName, path2Index, texteXML
my nettoie()
tell application "System Events" to tell disk item (thePack as text)
set typeID to (type identifier) as text
set pFold to package folder
set pName to name
end tell
if typeID is not in my permitted then
if my parleAnglais() then
error "“" & (docIwork as text) & "” is not an iWork’s document!"
else
error "«" & (docIwork as text) & "» n’est pas un document iWork !"
end if -- my parleAnglais()
end if -- typeID
if pFold then my expandFlat(thePack) (* an alias *)
try
if typeID is in my permittedKey then (*
special case Keynote *)
set path2Index to (thePack as text) & "Index.apxl"
else (*
Pages or Numbers *)
set path2Index to (thePack as text) & "Index.xml"
end if -- typeID starts …
set texteXML to my lis_Index(path2Index)
set texteXML to my decoupe(texteXML, "sf:auto-update=")
if (count of texteXML) > 1 then
repeat with i from 2 to count of texteXML
set itmI to item i of texteXML
if itmI starts with "false" then set item i of texteXML to "true" & text 6 thru -1 of itmI
end repeat
end if -- count of
set texteXML to my recolle(texteXML, "sf:one-shot=")
my enregistre(texteXML, path2Index)
my changeDoc2template(thePack) (* an alias *)
on error error_message number error_number
my nettoie()
if error_number is not -128 then my affiche(error_message)
end try
my nettoie()
end commun
--=====
on nettoie()
set typeID to missing value
end nettoie
--=====
on affiche(msg)
tell application "Finder"
activate
if my parleAnglais() then
display dialog msg buttons {"Cancel"} default button 1 giving up after 120
else
display dialog msg buttons {"Annuler"} default button 1 giving up after 120
end if -- parleAnglais()
end tell -- application
end affiche
--=====
on lis_Index(cheminXML0)
local cheminXML0, cheminXMLgz, txtXML
set cheminXMLgz to cheminXML0 & ".gz"
tell application "System Events"
if exists file cheminXMLgz then
if exists file cheminXML0 then delete file cheminXML0 (*
un curieux a pu dé-gzipper le fichier
• someone may have gunzipped the file *)
my expand(cheminXMLgz)
set txtXML to my lisIndex_xml(cheminXML0)
else if exists file cheminXML0 then
set txtXML to my lisIndex_xml(cheminXML0)
else
if typeID is in my permittedKey then (*
special case Keynote *)
if my parleAnglais() then
error "Index.apxl missing"
else
error "Il n'y a pas de fichier Index.apxl"
end if -- parleAnglais()
else (*
Pages or Numbers *)
if my parleAnglais() then
error "Index.xml missing"
else
error "Il n'y a pas de fichier Index.xml"
end if -- parleAnglais()
end if -- typeID
end if -- exists file cheminXMLgz
end tell -- to System Events
return txtXML
end lis_Index
--=====
on expand(f)
do shell script "gunzip " & quoted form of (POSIX path of (f))
end expand
--=====
on lisIndex_xml(f)
local t
try
set t to ""
set t to (read file f)
end try
return t
end lisIndex_xml
--=====
on enregistre(leTexte, nDoc)
local aliasNDoc
set aliasNDoc to nDoc as alias
write leTexte to aliasNDoc starting at 0
(*
As it is a template we may gzip the index. *)
do shell script "gzip " & quoted form of POSIX path of (nDoc)
end enregistre
--=====
on expandFlat(f) (* f is an alias *)
local zipExt, qf, d, nn, nz, fz, qfz
set zipExt to ".zip"
set qf to quoted form of POSIX path of f
tell application "System Events"
tell disk item (f as text)
set d to path of container
set nn to name
set nz to nn & zipExt
set fz to d & nz
if exists disk item fz then set name of disk item fz to nn & my horoDateur(modification date of file fz) & zipExt
set name to nz
end tell -- disk item
make new folder at end of folder d with properties {name:nn}
end tell -- System Events
set qfz to quoted form of POSIX path of fz
do shell script "unzip " & qfz & " -d " & qf & " ; rm " & qfz
end expandFlat
--=====
on changeDoc2template(f) (* f is an alias *)
local qf, d, nn, oldExt, templExt, template_loc, myTemplate_loc, p2t
set qf to quoted form of POSIX path of f
tell application "System Events"
tell disk item (f as text)
set d to path of container
set nn to name
set oldExt to name extension
end tell -- disk item
end tell -- System Events
if typeID is in my permittedKey then (*
special case Keynote *)
set templExt to "kth"
else (*
Pages or Numbers *)
set templExt to "template"
end if -- typeID starts …
set nn to text 1 thru -(1 + (count of oldExt)) of nn & templExt
tell application "System Events" to set name of disk item (f as text) to nn (* now the doc is a template *)
set template_loc to getLocale(oldExt, "Templates")
set myTemplate_loc to getLocale(oldExt, "My Templates")
set p2t to ((path to application support from user domain) as text) & "iWork:" & oldExt & ":" & template_loc & ":" & myTemplate_loc & ":"
tell application "Finder" to move alias (d & nn) to folder p2t with replacing
end changeDoc2template
--=====
(*
• Build a stamp from the modification date_time
*)
on horoDateur(dt)
local annee, mois, jour, lHeure, lesSecondes, lesMinutes
set annee to year of dt
set mois to month of dt as number (* existe depuis 10.4 *)
set jour to day of dt
set lHeure to time of dt
set lesSecondes to lHeure mod 60
set lHeure to round (lHeure div 60)
set lesMinutes to lHeure mod 60
set lHeure to round (lHeure div 60)
return "_" & annee & text -2 thru -1 of ("00" & mois) & text -2 thru -1 of ("00" & jour) & "-" & text -2 thru -1 of ("00" & lHeure) & text -2 thru -1 of ("00" & lesMinutes) & text -2 thru -1 of ("00" & lesSecondes)
(*
• Here, the stamp is "_YYYYMMDD-hhmmss" *)
end horoDateur
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on recolle(l, d)
local t
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to ""
return t
end recolle
--=====
on getLocale(a, x)
tell application a to return localized string x
end getLocale
--=====
on parleAnglais()
local z
try
tell application "Pages" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]
Yvan KOENIG (from FRANCE jeudi 19 mars 2009 09:26:58)