How to print Sequential Numbers like purchase order?
Thanks in advance
MacBookPro, Mac OS X (10.6.6)
MacBookPro, Mac OS X (10.6.6)
--[SCRIPT openAndNameInvoiceWithAnumber]
(*
Enregistrer le script en tant que Script : openAndNameInvoiceWithAnumber.scpt
déplacer le fichier créé dans le dossier
<VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Bibliothèque:Scripts:Applications:Pages:
Il vous faudra peut-être créer le dossier Pages et peut-être même le dossier Applications.
aller au menu Scripts , choisir Pages puis choisir openAndNameInvoiceWithAnumber
crée un nouveau document à partir du modèle personnel prédéfini
et renomme le document avec un nouveau numéro.
Il insère également le numéro de facture au début du document.
--=====
L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".
+++++++
Save the script as Script, Application or Application Bundle: openAndNameInvoiceWithAnumber.xxx
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Pages:
Maybe you would have to create the folder Pages and even the folder Applications by yourself.
go to the Scripts Menu, choose Pages, then choose openAndNameInvoiceWithAnumber
will create a new document from the defined user template
and name it with a new number.
It also insert the invoice number at the very beginning of the document.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
--=====
Yvan KOENIG (Vallauris, FRANCE)
2010/11/30
2010/12/20 edited to apply if the template is a flatfile one.
2011/01/11 added ability to build several invoices in a single call
*)
property theApp : "Pages"
property theExt : ""
property myTemplate : "ma_facture.template" (*
Adapter à vos besoins
Put your preferred template name *)
property fichierNum : "le_numéro.txt" (*
Adapter à vos gouts
Put your preferred text file name *)
--=====
on run
if theApp is "Pages" then
set theExt to "pages"
else
if my parleAnglais() then
error "The application “" & theApp & "” is not supported !"
else
error "L’application « " & theApp & " » n’est pas gérée"
end if
end if
if my parleAnglais() then
set nombredefactures to my askAnumber("Enter the number of consecutive invoices needed", 1, "i")
else
set nombredefactures to my askAnumber("Saisir le nombre de factures consécutives demandé", 1, "i")
end if
repeat nombredefactures times
my buildaninvoice()
end repeat
end run
--=====
on buildaninvoice()
set {p2myTemplate, numero} to my prepare()
set numero to text -5 thru -1 of ("0000" & numero) (* pour numéro de 5 chiffres *)
set UNTITLED_loc to my getLocalizedFrameWorksName(theApp, "Untitled")
tell application "Pages"
activate
try
close document UNTITLED_loc
end try
end tell -- to Pages
tell application "Pages"
activate
open p2myTemplate
set theDoc to numero & "." & theExt
set name of document 1 to theDoc
tell document 1
tell body text
if my parleAnglais() then
set paragraph 1 to "invoice #" & numero & return & paragraph 1
else
set paragraph 1 to "facture n°" & numero & return & paragraph 1
end if
end tell
end tell
end tell
end buildaninvoice
--=====
on getLocalizedFrameWorksName(theApp, x)
local p2bndl
set p2bndl to (path to application support as text) & "iWork '09:Frameworks:SFApplication.framework:Versions:A:Resources:"
set x_loc to my getLocalizedName(theApp, x, p2bndl)
return x_loc
end getLocalizedFrameWorksName
--=====
on getLocalizedFunctionName(theApp, x)
local p2bndl
set p2bndl to (path to application support as text) & "iWork '09:Frameworks:SFTabular.framework:Versions:A:Resources:"
set x_loc to my getLocalizedName(theApp, x, p2bndl)
return x_loc
end getLocalizedFunctionName
--=====
on getLocalizedName(aa, tt, ff)
tell application aa to return localized string tt from table "Localizable" in bundle file ff
end getLocalizedName
--=====
on prepare()
local d1, d2, p2d, containerOfTemplates, pathToTheTemplate, p2n, nn
tell application theApp
set d1 to localized string "Templates" (* nom local du dossier "Modèles" *)
set d2 to localized string "My Templates" (* nom local du dossier "Mes Modèles" *)
end tell -- theApp
set p2d to (path to application support from user domain) as Unicode text
set containerOfTemplates to p2d & "iWork:" & theApp & ":" & d1 & ":" & d2 & ":"
set pathToTheTemplate to containerOfTemplates & myTemplate & ":"
try
set pathToTheTemplate to pathToTheTemplate as alias
on error
if my parleAnglais() then
error "The template “" & pathToTheTemplate & "” is unavailable! Please make sure the template file “" & myTemplate & "” is installed in Numbers “Templates:My Templates” folder, then rerun this script."
else
error "Le modèle « " & pathToTheTemplate & " » est introuvable! Veuillez installer le fichier modèle « " & myTemplate & " » dans le dossier « Modèles:Mes modèles » de Numbers avant de relancer ce script."
end if
end try
tell application "System Events"
if class of disk item (pathToTheTemplate as text) is file then
(* flat file *)
set p2n to containerOfTemplates & fichierNum
if not (exists file p2n) then
make new file at end of folder containerOfTemplates with properties {name:fichierNum}
write "100" to file p2n (* mettez le numéro de départ de votre choix *)
end if -- not…
else
(* package *)
set p2n to "" & pathToTheTemplate & fichierNum
if not (exists file p2n) then
make new file at end of pathToTheTemplate with properties {name:fichierNum}
write "100" to file p2n (* mettez le numéro de départ de votre choix *)
end if -- not…
end if
end tell -- System Events
set nn to read file p2n
set nn to ((nn as integer) + 1) as text
write nn to file p2n starting at 1
return {pathToTheTemplate, nn}
end prepare
--=====
on parleAnglais()
local z
try
tell application theApp to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
(*
Asks for an entry and checks that it is an floating number
set myInteger to my askAnumber(Prompt, DefaultValue, "i")
set myFloating to my askAnumber(Prompt, DefaultValue, "f")
*)
on askAnumber(lPrompt, lDefault, IorF)
local lPrompt, lDefault, n
tell application (path to frontmost application as string)
if IorF is in {"F", "f"} then
set n to text returned of (display dialog lPrompt & " (" & (1.2 as text) & ")" default answer lDefault as text)
try
set n to n as number (* try to convert the value as an number *)
return n
on error
if my parleAnglais() then
display alert "The value needs to be a floating number." & return & "Please try again."
else
display alert "La valeur saisie doit être un nombre décimal." & return & "Veuillez recommencer."
end if
end try
else
set n to text returned of (display dialog lPrompt default answer lDefault as text)
try
set n to n as integer (* try to convert the value as an integer *)
return n
on error
if my parleAnglais() then
display alert "The value needs to be an integer." & return & "Please try again."
else
display alert "La valeur saisie doit être un nombre entier." & return & "Veuillez recommencer."
end if
end try -- 1st attempt
end if -- IorF…
end tell -- application
(*
Here if the first entry was not of the wanted class
second attempt *)
tell application (path to frontmost application as string)
if IorF is in {"F", "f"} then
set n to text returned of (display dialog lPrompt & " (" & (1.2 as text) & ")" default answer lDefault as text)
try
set n to n as number (* try to convert the value as an number *)
return n
on error
--
end try
else
set n to text returned of (display dialog lPrompt default answer lDefault as text)
try
set n to n as integer (* try to convert the value as an integer *)
return n
on error
--
end try -- 1st attempt
end if -- IorF…
end tell -- application
if my parleAnglais() then
error "The value you entered was not numerical !" & return & "Goodbye !"
else
error "La valeur saisie n’est pas numérique !" & return & "Au revoir !"
end if
end askAnumber
--=====
--[/SCRIPT]
--
jaxjason wrote:
We should be a little clearer on the macro concept. Numbers does not run EXCEL VBA macros, applescript is the equivalent for Apple products. There are a few "Excel Macro to Applescript" guides online that can assist in re-writting your XL macros to Applescript.
How to print Sequential Numbers like purchase order?