--(SCRIPT Pages->Word Droplet.app]
(*
You may set the script so it creates uniques time stamped names.
You may set the timestamp with or without the seconds.
*)
property theApp : "Pages"
property types : {{".doc", "Microsoft Word 97 - 2004 document"}, {".pdf", "SLDocumentTypePDF"}, {".txt", "SLDocumentTypePlainText"}, {".rtf", "SLDocumentTypeRichText"}, {".rtfd", "SLDocumentTypeRichTextBundle"}}
property withSeconds : false (*
false --> #YYYYMMDD-hhmm
true --> #YYYYMMDD-hhmmss
*)
property uniqueName : false (*
false --> myFile.doc
true --> myFile#YYYYMMDD-hhmm.doc
or myFile#YYYYMMDD-hhmmss.doc
*)
--=============
on open files_
repeat with file_ in files_
if (file_ as text) does not end with ".pages" then
error "Selected document must be a Pages document"
end if
tell application "Finder"
set extension hidden of file_ to true
end tell
set {newExt, newType} to item 1 of types (*
item 1 = doc
item 2 = pdf
item 3 = txt
item 4 = rtf
item 5 = rtfd *)
tell application theApp
open file_
set thePath to path of document 1
try
copy thePath to thePath
on error (*
The document has not been saved. Before proceeding, please save as a Pages Pages document *)
tell application theApp
save front document
(*
Saving the open document as a Pages Document is possible only in Mac OS X 10.4 or higher
*)
delay 0.2
set thePath to path of document 1
end tell -- theApp
end try
end tell --theApp
tell application theApp to set theName to name of document 1
if uniqueName then
set newName to (text 1 thru -7 of theName) & (my horodate()) & newExt (* Insert unique ID and replace the "pages" extension by the newExt one *)
else
set newName to (text 1 thru -1 of theName) & newExt (* Replace the "pages" extension by the newExt one *)
end if
tell application "System Events" to set theCont to (path of container of disk item thePath) as Unicode text
(* CAUTION, When saving, Pages does not backup the existing document.
It overwrites it with the new document. *)
tell application theApp to save front document as newType in (theCont & newName) (* save as newType document *)
tell application theApp
tell document 1
if not modified then
close
end if
end tell
end tell
--tell application "Finder"
--set extension hidden of item (newName) to true
--end tell
end repeat
end open
--=============
on horodate()
if withSeconds then
return (do shell script "date " & quote & "+%Y%m%d-%H%M%S" & quote) & "." (* period required *)
else
return (do shell script "date " & quote & "+%Y%m%d-%H%M" & quote) & "." (* period required *)
end if
end horodate
--=============
--[/SCRIPT]