leading zeros help!
Mac OS X (10.4.11)
Mac OS X (10.4.11)
KOENIG Yvan wrote:
Everybody is not living in the USA.
(*
Enregistrer le script en tant qu'Application ou Progiciel : zeroHead.app
déplacer l'application créée dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Copier les nombres à formater dans le presse-papiers
Placez le curseur où ça vous chante dans Numbers
menu Scripts > zeroHead
Le script collera les nombres formatés selon le masque zeroHead
+++++++
Save the script as an Application or an Application Bundle: zeroHead.app
Move the newly created application into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
Copy the numbers to format in the clipboard
Put the cursor where you wish in Numbers
menu Scripts > zeroHead
The script will paste the numbers after applying the mask.
Yvan KOENIG le 7 mars 2008
*)
property listeLignes : {}
property listeTempAvant : {}
property listeTempApres : {}
property listeApres : {}
property nbDigits : 5
property zeroes : ""
property myZero : "O" (* upper O, you may use Ø = slashedZero *)
property theApp : "Numbers"
property menuFenetre : 10
property premierNom : 6
property nomDuDocActif : ""
--=============
on run
tell application "System Events" to if not (UI elements enabled) then set (UI elements enabled) to true (*
Active le GUI scripting
• Enable GUI scripting *)
if zeroes is "" then
repeat nbDigits times
set zeroes to zeroes & myZero
end repeat
end if
my nettoie()
my controleVersion()
set nomDuDocActif to my getFrontDoc()
if nomDuDocActif = "" then return
try
set textdatas to (the clipboard) as Unicode text
on error (*
The clipboard was empty *)
return
end try
set my listeLignes to paragraphs of textdatas
try
if textdatas contains tab then (*
plusieurs colonnes *)
repeat with ligne in my listeLignes
set my listeTempAvant to my decoupe(ligne as text, tab)
set my listeTempApres to {}
repeat with nn in my listeTempAvant
copy my applyTheMask(nn) to end of my listeTempApres
end repeat
copy my recolle(my listeTempApres, tab) to end of my listeApres
end repeat
else (*
une seule colonne *)
repeat with nn in my listeLignes
copy my applyTheMask(nn) to end of my listeApres
end repeat
end if
set the clipboard to my recolle(my listeApres, return)
my pasteIt()
my nettoie()
end try
end run
--=============
on pasteIt()
tell application theApp to activate
tell application "System Events" to tell (first process whose title is theApp)
click menu item nomDuDocActif of menu 1 of menu bar item menuFenetre of menu bar 1
keystroke "v" using {command down}
end tell
end pasteIt
--=============
on applyTheMask(n)
copy n as text to n
if n is not "" then
if n contains "0" then set n to my recolle(my decoupe(n, "0"), myZero) (* replaces zero by myZero *)
set n to text -nbDigits thru -1 of (zeroes & n)
end if
return n as text
end applyTheMask
--=============
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 nettoie()
set my listeLignes to {}
set my listeTempAvant to {}
set my listeTempApres to {}
set my listeApres to {}
set nomDuDocActif to ""
end nettoie
--=============
(*
Get the name of the active document
*)
on getFrontDoc()
local nw, mm
tell application theApp to activate
tell application "System Events" to tell (first process whose title is theApp)
set nw to name of every menu item of menu 1 of menu bar item menuFenetre of menu bar 1
if (count of nw) < premierNom then
set mm to ""
else
repeat with i from premierNom to count of nw
set mm to item i of nw
if (value of attribute "AXMenuItemMarkChar" of menu item mm of menu 1 of menu bar item menuFenetre of menu bar 1) is not in {"", "•"} then exit repeat
end repeat
end if -- (count of nw)…
end tell
return mm
end getFrontDoc
--=============
on controleVersion()
local v
try
set v to version of application theApp
set menuFenetre to 10 (* index of the Windows menu *)
set premierNom to 6 (* index of the first docName in the list of menu names
The list contains one more item than the displayed menu *)
on error (*
• We are here if Numbers ignores the instruction get version *)
tell application "System Events" to set v to get version of (get (application file of (get first process whose title is theApp)))
if v starts with "1" then
set menuFenetre to 10
set premierNom to 6
else (* ready for a Numbers v2 ignoring AppleScript *)
set menuFenetre to 10
set premierNom to 6
end if
end try
end controleVersion
--=============
--[/SCRIPT]
leading zeros help!