Why does Pages quit unexpectedly while using the SFWordProcessing plugin?
Intel IMac Core 2 Duo, Mac OS X (10.6)
Intel IMac Core 2 Duo, Mac OS X (10.6)
fruhulda wrote:
Have you looked at your fonts in the Fontbook? In the File menu you can Validate fonts. If they are OK keep them, the other should be trashed.
-- [SCRIPT listOfPicturesWithSize]
(*
Save the script as Application (Application Bundle if you want to use it on a MacIntel)
Store it on the Desktop.
Drag and drop the icon of a Pages document on the script icon.
You may also double click the script's icon.
The script will build a list of embedded picture files.
The list is available on the desktop in "listof_embeddedpictures.txt"
Open it then copy its contents at end of the Pages document so that the page numbering will not be modified.
If you want to put the list at the beginning, insert a page break to create a target blank page before running the script.
Yvan KOENIG (Vallauris, FRANCE)
2009/09/09
*)
property permitted4 : {"com.apple.iWork.pages.sffpages", "com.apple.iWork.pages.sfftemplate"}
property permitted5 : {"com.apple.iwork.pages.pages", "com.apple.iwork.pages.template"}
property permitted : permitted5 & permitted4
property nomDuRapport : "listof_embeddedpictures.txt"
property typeID : missing value
property wasFlat : missing value
property listePages : {}
property listeImages : {}
property liste1 : {}
--=====
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 an iWork’s document"
else
set myPrompt to "Choisir un document iWork"
end if -- parleAnglais
if 5 > (system attribute "sys2") then (*
if Mac Os X 10.4.x *)
set allowed to my permitted
else (*
it's Mac OS X 10.5.x with a bug with Choose File *)
set allowed to {}
end if -- 5 > (system…
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(thePack) (*
• thePack is an alias *)
local pFold, pName, path2Index, texteXML
my nettoie()
set theTruePack to thePack as text
tell application "System Events" to tell disk item theTruePack
set typeID to (type identifier) as text
set pFold to package folder
set pName to name
end tell
if typeID is not in my permitted then
if my parleAnglais() then
error "“" & (docIwork as text) & "” is not a Pages document!"
else
error "«" & (docIwork as text) & "» n’est pas un document Pages !"
end if -- my parleAnglais()
end if -- typeID
if pFold then
set wasFlat to false
else
set wasFlat to true
set thePack to my expandFlat(thePack) (* an alias *)
log thePack
end if
try
set path2Index to (thePack as text) & "Index.xml"
set texteXML to my lis_Index(path2Index)
(* here code to scan the text *)
set line_feed to ASCII character (10)
if texteXML contains line_feed then set texteXML to my remplace(texteXML, line_feed, return)
if texteXML contains return then set texteXML to my remplace(texteXML, return & return, return)
set texteXML to my supprime(texteXML, tab)
set balise1 to "<sl:page-group sl:page=" & quote
set balise2 to "<sf:media"
set balise3 to "<sf:naturalSize sfa:w=" & quote
set balise4 to "<sf:data sf:path=" & quote
set balise5 to quote & "/>"
set balise7 to "sf:size=" & quote
if texteXML does not contain balise4 then
if my parleAnglais() then
error "The document “" & theTruePack & "” doesn’t embed picture !" number 8001
else
error "Le document « " & theTruePack & " » ne contient pas d’image !" number 8001
end if
else if texteXML contains balise1 then
copy "nomImage" & tab & "page #" & tab & "naturalWidth" & tab & "naturalHeight" & tab & "trueWidth" & tab & "trueHeight" & tab & "fileSize (kBytes)" to end of my listeImages
set my listePages to my decoupe(texteXML, balise1)
repeat with i from 2 to count of my listePages
set itmi to item i of my listePages
set pageNum to item 1 of my decoupe(itmi, quote)
set my liste1 to my decoupe(itmi, balise2)
repeat with k from 2 to count of my liste1
set itmk to item k of my liste1
if itmk contains balise4 then -- on a une image
set liste3 to my decoupe(itmk, balise3)
set liste3 to my decoupe(item 2 of liste3, quote)
set wNatural to item 1 of liste3
set hNatural to item 3 of liste3
set w to item 5 of liste3
set h to item 7 of liste3
set liste3 to my decoupe(itmk, balise4)
set itmk to item 1 of my decoupe(item 2 of liste3, balise5)
set nomImage to item 1 of my decoupe(itmk, quote)
set fSize to item -1 of my decoupe(itmk, balise7)
copy nomImage & tab & pageNum & tab & wNatural & tab & hNatural & tab & w & tab & h & tab & (fSize div 1024) to end of my listeImages
end if
set liste3 to {}
end repeat
end repeat
end if -- balise4
set rapport to (my recolle(my listeImages, return)) as text
set p2d to path to desktop
set p2r to (p2d as Unicode text) & nomDuRapport
tell application "System Events"
if exists (file p2r) then delete (file p2r)
make new file at end of p2d with properties {name:nomDuRapport}
end tell -- "System Events"
write rapport to (p2r as alias)
if wasFlat then tell application "System Events" to delete file (thePack as text) -- delete temporary package
tell application "Numbers" to open file p2r
on error error_message number error_number
my nettoie()
if error_number is not -128 then my affiche(error_message)
end try
my nettoie()
end commun
--=====
on nettoie()
set typeID to missing value
set wasFlat to missing value
set my listePages to {}
set my listeImages to {}
set my liste1 to {}
end nettoie
--=====
on affiche(msg)
tell application "Finder"
activate
if my parleAnglais() then
display dialog msg buttons {"Cancel"} default button 1 giving up after 120
else
display dialog msg buttons {"Annuler"} default button 1 giving up after 120
end if -- parleAnglais()
end tell -- application
end affiche
--=====
on lis_Index(cheminXML0)
local cheminXML0, cheminXMLgz, txtXML
set cheminXMLgz to cheminXML0 & ".gz"
tell application "System Events"
if exists file cheminXMLgz then
if exists file cheminXML0 then delete file cheminXML0 (*
un curieux a pu dé-gzipper le fichier
• someone may have gunzipped the file *)
my expand(cheminXMLgz)
set txtXML to my lisIndex_xml(cheminXML0)
else if exists file cheminXML0 then
set txtXML to my lisIndex_xml(cheminXML0)
else
if my parleAnglais() then
error "Index.xml missing"
else
error "Il n'y a pas de fichier Index.xml"
end if -- parleAnglais()
end if -- exists file cheminXMLgz
end tell -- to System Events
return txtXML
end lis_Index
--=====
on expand(f)
do shell script "gunzip " & quoted form of (POSIX path of (f))
end expand
--=====
on lisIndex_xml(f)
local t
try
set t to ""
set t to (read file f)
end try
return t
end lisIndex_xml
--=====
on expandFlat(f) (* f is an alias *)
local zipExt, qf, d, nn, nz, fz, qfz
tell application "Finder" to set newF to (duplicate f without replacing) as alias -- create a temporary item which will be changed as package
set zipExt to ".zip"
set qf to quoted form of POSIX path of newF
tell application "System Events"
tell disk item (newF as text)
set d to path of container
set nn to name
set nz to nn & zipExt
set fz to d & nz
if exists disk item fz then set name of disk item fz to nn & my horoDateur(modification date of file fz) & zipExt
set name to nz
end tell -- disk item
make new folder at end of folder d with properties {name:nn}
end tell -- System Events
set qfz to quoted form of POSIX path of fz
do shell script "unzip " & qfz & " -d " & qf & " ; rm " & qfz
return newF (* path to the temporary package *)
end expandFlat
--=====
(*
• Build a stamp from the modification date_time
*)
on horoDateur(dt)
local annee, mois, jour, lHeure, lesSecondes, lesMinutes
set annee to year of dt
set mois to month of dt as number (* existe depuis 10.4 *)
set jour to day of dt
set lHeure to time of dt
set lesSecondes to lHeure mod 60
set lHeure to round (lHeure div 60)
set lesMinutes to lHeure mod 60
set lHeure to round (lHeure div 60)
return "_" & annee & text -2 thru -1 of ("00" & mois) & text -2 thru -1 of ("00" & jour) & "-" & text -2 thru -1 of ("00" & lHeure) & text -2 thru -1 of ("00" & lesMinutes) & text -2 thru -1 of ("00" & lesSecondes)
(*
• Here, the stamp is "_YYYYMMDD-hhmmss" *)
end horoDateur
--=====
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
--=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local l
set AppleScript's text item delimiters to d1
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to ""
return t
end remplace
--=====
(*
removes every occurences of d in text t
*)
on supprime(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 as text)
end supprime
--=====
on parleAnglais()
local z
try
tell application "Pages" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
-- [/SCRIPT]
--
Why does Pages quit unexpectedly while using the SFWordProcessing plugin?