Handling tab delimited files.
Mac mini, Mac OS X (10.6.6)
Mac mini, Mac OS X (10.6.6)
(1) we may disable the tool appending the extension. This open the door to wrong manual extension appending.
--[SCRIPT openhtmlxls]
(*
Enregistrer le script en tant que Script ou Application : openhtmlxls.xxx
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:
Aller au menu Scripts , choisir Numbers puis choisir “openhtmlxls”
Le script demande de sélectionner un fichier Excel de structure html.
Il l’ouvre dans TextEdit, sélectionne tout puis copie dans le Presse-papiers.
Il crée un nouveau document à partir du modèle "Vide" de Numbers.
Il supprime la table crée par défaut et colle.
--=====
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”.
Sous 10.6.x,
aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
--=====
Save the script as a Script or an Application : openhtmlxls.xxx
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:
Go to the Scripts Menu, choose Numbers, then choose “openhtmlxls”
The script ask you to select an Excel document structured as html.
It open it in TextEdit, Select All and Copy to the clipboard.
It create a new document from the Numbers' blank template.
It delete the default table then paste.
--=====
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.
Under 10.6.x,
go to the General panel of AppleScript Editor’s Preferences dialog box
and check the “Show Script menu in menu bar” option.
--=====
Yvan KOENIG (VALLAURIS, France)
2011/03/30
*)
--=====
on run
run script doyourduty
-- my doyourduty()
end run
--=====
script doyourduty
-- on doyourduty()
local unxlshtml, myNewDoc
my activateGUIscripting()
tell application (path to frontmost application as text)
if my parleAnglais() then
set unxlshtml to choose file with prompt "Choose an html xls file" of type "com.microsoft.excel.xls" without invisibles
else
set unxlshtml to choose file with prompt "Choisir un fichier Excel de type Html" of type "com.microsoft.excel.xls" without invisibles
end if -- parleAnglais
end tell
-- set unxlshtml to ("" & (path to desktop & "report1301488888645.xls")) as alias
tell application "TextEdit"
open unxlshtml
my raccourci("TextEdit", "a", "c") -- Select All
my raccourci("TextEdit", "c", "c") -- Copy
close document 1
end tell
set myNewDoc to my makeAnIworkDoc("Numbers")
tell application "Numbers" to tell document myNewDoc to tell sheet 1
delete table 1
end tell
my raccourci("Numbers", "v", "c") -- Paste
-- end doyourduty
end script
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
on activateGUIscripting()
(* to be sure than GUI scripting will be active *)
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true
end tell
end activateGUIscripting
--=====
(*
Creates a new iWork document from the Blank template and returns its name.
example:
set myNewDoc to my makeAnIworkDoc(theApp)
*)
on makeAnIworkDoc(the_app)
local maybe, pathto_theApp, nb_doc, doc_name
if the_app is "Pages" then
tell application "Pages"
set nb_doc to count of documents
make new document with properties {template name:item 1 of templates}
end tell
else if the_app is "Numbers" then
tell application "System Events" to set maybe to the_app is in title of every application process
if not maybe then tell application theApp to activate
tell application "System Events"
set pathto_theApp to get application file of application process the_app
end tell
tell application "Numbers"
set nb_doc to count of documents
open ((pathto_theApp as text) & "Contents:Resources:Templates:Blank.nmbtemplate:")
end tell
else
if my parleAnglais(theApp) then
error "The application “" & the_app & "“ is not accepted !"
else
error "l’application « " & the_app & " » n’est pas gérée !"
end if
end if
tell application the_app
repeat until (count of documents) > nb_doc
delay 0.1
end repeat
set doc_name to name of document 1
end tell -- the_App
return doc_name
end makeAnIworkDoc
--=====
(*
==== Uses GUIscripting ====
*)
(*
This handler may be used to 'type' text, invisible characters if the third parameter is an empty string.
It may be used to 'type' keyboard raccourcis if the third parameter describe the required modifier keys.
I changed its name « shortcut » to « raccourci » to get rid of a name conflict in Smile.
*)
on raccourci(a, t, d)
local k
tell application a to activate
tell application "System Events" to tell application process a
set frontmost to true
try
t * 1
if d is "" then
key code t
else if d is "c" then
key code t using {command down}
else if d is "a" then
key code t using {option down}
else if d is "k" then
key code t using {control down}
else if d is "s" then
key code t using {shift down}
else if d is in {"ac", "ca"} then
key code t using {command down, option down}
else if d is in {"as", "sa"} then
key code t using {shift down, option down}
else if d is in {"sc", "cs"} then
key code t using {command down, shift down}
else if d is in {"kc", "ck"} then
key code t using {command down, control down}
else if d is in {"ks", "sk"} then
key code t using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
key code t using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
key code t using {command down, shift down, option down}
end if
on error
repeat with k in t
if d is "" then
keystroke (k as text)
else if d is "c" then
keystroke (k as text) using {command down}
else if d is "a" then
keystroke k using {option down}
else if d is "k" then
keystroke (k as text) using {control down}
else if d is "s" then
keystroke k using {shift down}
else if d is in {"ac", "ca"} then
keystroke (k as text) using {command down, option down}
else if d is in {"as", "sa"} then
keystroke (k as text) using {shift down, option down}
else if d is in {"sc", "cs"} then
keystroke (k as text) using {command down, shift down}
else if d is in {"kc", "ck"} then
keystroke (k as text) using {command down, control down}
else if d is in {"ks", "sk"} then
keystroke (k as text) using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
keystroke (k as text) using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
keystroke (k as text) using {command down, shift down, option down}
end if
end repeat
end try
end tell
end raccourci
--=====
--[/SCRIPT]
--
briegull wrote:
Thank you so very much, Yvan. This is a problem that has vexed me for a while.
Without the script, though, I had tried opening it in text edit, copying it, and pasting it into Numbers. And the cells for a given record went down, not across, one below another, record after record all in column A. They still do.. Maybe that's some setting I can't find in Numbers but it worked with your script!!
Handling tab delimited files.