--
-- [SCRIPT html2Pages]
(*
Save the script as an Application or an Application Bundle.
Application Bundle if you want to use it on a MacIntel.
Store it on the Desktop.
Drag and drop the icon of a html document on the script icon.
You may also double click the script's icon.
The script will open it in Safari then copy paste into a Pages WP document.
Yvan KOENIG (Vallauris, FRANCE)
24 juin 2009
*)
property permitted : {"public.html"}
--=====
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 a Html document"
else
set myPrompt to "Choisir un document Html"
end if -- parleAnglais
set allowed to my permitted
my commun(choose file with prompt myPrompt of type allowed without invisibles) (* 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(theFile)
my activateGUIscripting()
tell application "Safari" to open theFile
my shortcut("Safari", "ac", "c")
set myNewDoc to my makeAnIworkDoc("Pages")
my shortcut("Pages", "v", "c")
end commun
--=====
on makeAnIworkDoc(theApp)
local t, n
if theApp is "Pages" then
set t to ((path to applications folder as text) & "iWork '09:Pages.app:Contents:Resources:Templates:Blank.template:") as alias
else if theApp is "Numbers" then
set t to ((path to applications folder as text) & "iWork '09:Numbers.app:Contents:Resources:Templates:Blank.nmbtemplate:") as alias
else
if my parleAnglais(theApp) then
error "The application “" & a & "“ is not accepted !"
else
error "l’application « " & a & " » n’est pas gérée !"
end if
end if
tell application theApp
set n to count of documents
open t
repeat
if (count of documents) > n then
exit repeat
else
delay 0.1
end if
end repeat
set n to name of document 1
end tell -- theApp
return n
end makeAnIworkDoc
--=====
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()
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
end tell
end activateGUIscripting
--=====
(*
==== Uses GUIscripting ====
*)
on shortcut(a, t, d)
local k
tell application a to activate
tell application "System Events" to tell application process a
repeat with k in t
if d = "c" then
keystroke (k as text) using {command down}
else if d contains "c" then
if d contains "s" then
if d contains "k" then
keystroke (k as text) using {command down, shift down, control down}
else
keystroke (k as text) using {command down, shift down}
end if
else if d contains "k" then
keystroke (k as text) using {command down, control down}
end if
end if
end repeat
end tell
end shortcut
--=====
--[SCRIPT]
Yvan KOENIG (from FRANCE mercredi 24 juin 2009 10:37:51)