Puisqu'il semble que la piste envisagée est bouchée, je poste mon
script en l'état dans l'espoir que l'un de vous ayant accès à iWork
et à un réseau pourra le tester.
Sur le forum de discussion US dédié aux composants d'iWorks, les
utilisateurs se plaignent de la façon dont se comporte les programmes
mais personne ne répond lorsque je leur demande de tester le script.
Comme il y a deux instructions "do shell Script" je ne suis pas HS ;-)
--(SCRIPT iWork_sharing.app]
(*
Save the script as an Application Bundle with the name
iWork_sharing .app
Assuming that theApp may be Keynote, Numbers or Pages,
to use it with the application theApp, put a copy of the script in
the folder
<startup
Volume>:Users:<yourAccount>:Library:Scripts:Applications:theApp:
Maybe you would have to create the folder theApp and even the folder
Applications by yourself.
To use it,
goto Scripts > theApp > iWork_sharing
If you choose "Open" you will be asked to select the document to open.
The script will copy it into the subfolder "iWork sharing ƒ" in the
Documents folder.
It will also create a text file containing the path to the container
of the original document.
It will remove the Index.xml file from the original bundle so nobody
would be able to use it.
It will open the doc from its copy.
If you choose "Save and free"
the script will save the document in its local subfolder,
move it to the original container,
close the open document.
If keepArchive is defined as true, it will pack the local document in
a date stamped archive.
At last, it remove the two "standard" local files.
Yvan KOENIG le 4 mars 2008
revised 18 avril 2008
*)
property permitted : missing value
property theApp : missing value
property nameExt : missing value
property theExt : missing value
property mNum : missing value
property beg : missing value
property keepArchive : true (*
• true = keep a zip archive of the doc in the local folder
• false = doesn't keep an archive *)
-- =============
on run
set p2m to path to me
tell application "System Events" to set theApp to name of container
of p2m
if theApp is not in {"Keynote", "Numbers", "Pages"} then return (*
• Does nothing if it is installed in a wrong folder.
*)
if theApp is "Pages" then
set permitted to {"com.apple.iwork.pages.pages"}
set nameExt to "pages"
else if theApp is "Keynote" then
set permitted to {"com.apple.iwork.keynote.keynote"}
set nameExt to "keynote"
else
set permitted to {"com.apple.iwork.numbers.numbers"}
set nameExt to "numbers"
set {mNum, beg} to {10, 6} (*
• mNum = index of the Windows menu
• beg = index of the first docName in the list of menu names . This
list contains one more item than the displayed menu *)
end if -- theApp
if my parleAnglais() is false then
set msg to "Que voulez vous faire ?"
set {btn3, btn2, btn1} to {"Annuler", "Enregistrer et libérer",
"Ouvrir"}
else
set msg to "What want you to do ?"
set {btn3, btn2, btn1} to {"Cancel", "Save and Free", "Open"}
end if
--tell application (path to frontmost application as string) to set
choix to display dialog msg buttons {btn3, btn2, btn1} default button
btn1
tell application "Finder"
activate
set choix to display dialog msg buttons {btn3, btn2, btn1} default
button btn1
end tell
set choix to button returned of choix
set nomDossier to "iWork sharing ƒ"
set p2d to (path to documents folder) as Unicode text
set monDossier to p2d & nomDossier & ":" (*
• the colon is important *)
tell application "System Events" to if not (exists folder
monDossier) then make new folder at end of folder p2d with properties
{name:nomDossier}
if choix is btn1 then
my ouvreUnDocument(monDossier)
else
my |enregistre_et_libère|(monDossier)
end if
end run
-- =============
on ouvreUnDocument(dossierLocal)
local theDoc, nomDoc, |dossierPartagé|, documentLocal
tell application "System Events"
set theDoc to choose file of type permitted
set the_Doc to theDoc as Unicode text
set flag1 to exists file (the_Doc & "Index.xml.gz")
set flag2 to exists file (the_Doc & "Index.xml")
end tell -- System Events
if flag1 or flag2 then
tell application "System Events"
set nomDoc to name of theDoc
set |dossierPartagé| to (path of container of theDoc)
set documentLocal to dossierLocal & nomDoc
if exists file documentLocal then delete file documentLocal
if exists file (documentLocal & ".txt") then delete file
(documentLocal & ".txt")
make new file at end of folder dossierLocal with properties
{name:nomDoc & ".txt"}
end tell -- System Events
write |dossierPartagé| as «class utf8» to file (documentLocal &
".txt")
tell application "Finder"
duplicate theDoc to folder dossierLocal
open (documentLocal as alias)
end tell
tell application "System Events"
if flag1 is true then delete file (the_Doc & "Index.xml.gz")
if flag2 is true then delete file (the_Doc & "Index.xml")
end tell
if my parleAnglais() is false then
my dialogue("Désormais le document « " & the_Doc & " » ne peut
être ouvert par un autre utilisateur.")
else
my dialogue("Now the document “" & the_Doc & "” can't be open
by an other user.")
end if
else
if my parleAnglais() is false then
error ("Le document « " & the_Doc & " » est déjà en service.")
else
error ("The document “" & the_Doc & "” is already in use.")
end if
end if
end ouvreUnDocument
-- =============
on |enregistre_et_libère|(dossierLocal)
local nomDuDoc, documentLocal, flag1, flag2, |dossierPartagé|
set nomDuDoc to my getFrontDoc() (*
• Grab the name of the frontmost document *)
set documentLocal to dossierLocal & nomDuDoc (*
• Don't put a terminal colon *)
tell application "System Events"
set flag1 to exists file package documentLocal
set flag2 to exists file (documentLocal & ".txt")
end tell -- System Events
if flag1 and flag2 then
my enregistre(nomDuDoc) (*
• Save the doc in the local folder *)
my ferme(nomDuDoc) (*
• Close the doc *)
if keepArchive is true then my zipIt(documentLocal, my horodate()) (*
• If the property keepArchive is set to true, archive the local
document in a .zip date stamped archive *)
set |dossierPartagé| to (read file (documentLocal & ".txt")) as
Unicode text
set |documentPartagé| to |dossierPartagé| & nomDuDoc & ":"
tell application "System Events" to if exists file |
documentPartagé| then delete file |documentPartagé|
tell application "Finder" to duplicate (documentLocal as alias) to
(folder |dossierPartagé|) (*
• System Events can't duplicate
• Move the document back to its source folder *)
tell application "System Events"
delete file documentLocal (*
• delete the local iWork's document *)
delete file (documentLocal & ".txt") (*
• delete the local text document containing the path to source
container *)
end tell -- System Events
else
if my parleAnglais() is false then
error ("Le document « " & nomDuDoc & " » n’est pas à notre
disposition.")
else
error ("The document “" & nomDuDoc & "” is not our property.")
end if -- language
end if -- flag1 and flag2 …
end |enregistre_et_libère|
(* =============
Get the frontMost document
*)
on getFrontDoc()
local nw, nDoc
if theApp is in {"Keynote", "Pages"} then
tell application theApp to set nDoc to name of document 1
else
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 mNum
of menu bar 1
if (count of nw) < beg then
set nDoc to ""
else
repeat with i from beg to count of nw
set nDoc to item i of nw
if (value of attribute "AXMenuItemMarkChar" of menu item nDoc of
menu 1 of menu bar item mNum of menu bar 1) is not "" then exit repeat
end repeat
end if -- (count of nw)…
end tell -- process…
end if
return nDoc
end getFrontDoc
(* =============
• Save the document as an iWork's one
*)
on enregistre(nDoc)
if theApp is in {"Keynote", "Pages"} then
tell application theApp to save document nDoc
else
tell application theApp to activate
tell application "System Events" to tell (first process whose title
is theApp)
click menu item nDoc of menu 1 of menu bar item mNum of menu bar 1 (*
• brings window n to front *)
keystroke "s" using {command down}
end tell -- process…
end if -- theApp
end enregistre
(* =============
• Close the frontmost document
*)
on ferme(nDoc)
if theApp is in {"Keynote", "Pages"} then
tell application theApp to close document nDoc
else
tell application theApp to activate
tell application "System Events" to tell (first process whose title
is theApp)
click menu item nDoc of menu 1 of menu bar item mNum of menu bar 1 (*
• brings window n to front *)
keystroke "w" using {command down}
end tell -- process…
end if -- theApp
end ferme
-- =============
on dialogue(t)
beep 1
tell application (path to frontmost application as string) to
display dialog t buttons " OK " default button 1
end dialogue
--=============
on parleAnglais()
(* pour synchroniser la langue utilisée par le script
avec celle utilisée par l'application pilotée *)
local z
try
tell application theApp to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z = "Cancel")
end parleAnglais
--=============
on horodate()
return (do shell script "date " & quote & "+_%Y%m%d-%H%M%S" & quote)
& "." (* period required *)
end horodate
--=============
on zipIt(f, u)
local n, d, nZ, source, dest
tell application "System Events" to tell disk item f
set n to name
set d to path of container
end tell (*
• Here d is an Unicode HFS path *)
set nZ to (text 1 thru -(2 + (length of nameExt)) of n) & u &
nameExt & ".zip"
set dest to d & nZ
tell application "System Events"
if exists disk item dest then delete disk item dest
make new file at end of folder d with properties {name:nZ,
kind:"ZIP archive"}
end tell
set source to quoted form of POSIX path of f
set dest to quoted form of POSIX path of dest
do shell script "ditto -ck " & source & " " & dest
end zipIt
--=============
--[/SCRIPT]
_______________________________________________
archives :
http://listes.patpro.net/list/sshfr.fr.html
http://listes.patpro.net/mailman/listinfo/script_shell_fr