Pie chart importing script-success!!!!
Pie chart importing script-success!!!!
- Subject: Pie chart importing script-success!!!!
- From: "Rips Ethan J" <email@hidden>
- Date: Tue, 15 Oct 2002 17:00:25 -0400
- Thread-topic: Pie chart importing script-success!!!!
Hello, all-
[Length warning]
At long last, I've gotten the OS 9.2.2 (Applescript 1.8.3) version of my
script to work. Special thanks to Arthur Knapp, Caryn Francis, Goran Ehn &
John Delacour for your help!!
I wonder if I might impose on you again & ask for your thoughts on ways to
optimize this?
Next phase: The OS X version (thanks for the perl code, John-I'm amazed at its
speed! More about this later, I suspect... ;-) ).
Here it is:
--path to Quark documents is assigned to var docPath
property docPath :
(choose folder with prompt "Select folder of current Fact Sheets:")
--Assign
the folder's path to var imagepath:
global imagePath
set imagePath to (choose
folder with prompt "Select the folder of current pie charts:")
--destination
folder for completed fact sheets
global destFolder
set destFolder to (choose
folder with prompt "Select the destination folder for the fact sheets:")
--generate 4-digit code for date
global dateCode
copy ((offset of (the month
of (current date)) in ,
"jan feb mar apr may jun jul aug sep oct nov dec ") +
3) / 4 ,
as integer to mm
if mm < 10 then copy "0" & mm as string to mm
if
((mm = 10) or (mm > 10)) then copy mm as string to mm
copy (year of (current
date) as string) to yy
set yr to (yy's text from character 3 to character 4)
copy mm & yr to dateCode
dateCode
--Convert each Finder object (file name) to
alias
tell application "Finder"
--sort list by name
set docList to sort
(every file of docPath) by name
--then coerce each item to alias
repeat with
i in docList
set i's contents to i as alias
end repeat
--Yields list of
aliases
docList
end tell
--Convert each Finder object (names of files in
imageList) to alias
--NEED TO SUBSTITUTE NON-AS CODE TO SORT CONTENTS OF
IMAGEPATH FOR OS X COMPATIBILITY
tell application "Finder"
--sort list by
name
set imageList to sort (every file of imagePath) by name
--then coerce
each item to alias
repeat with i in imageList
set i's contents to i as
alias
end repeat
--Yields list of aliases
imageList
end tell
set x to
(number of items in docList)
repeat with i from 1 to x
set j to i
repeat
until j > i
set docAlias to item i of docList
set docName to item 2 of
(getFileName(docPath, docAlias))
set imageAlias to item j of imageList
set
pieName to item 2 of (getFileName(imagePath, imageAlias))
insertPie(docAlias, docName, pieName)
set j to (j + 1)
end repeat
end
repeat
--handler accesses filename & concatenates to imagePath to set up pie
chart insertion (for each file)
on getFileName(pathname, fAlias)
try
set
fAlias to ("" & pathname & fAlias)
on error errMsg number errNum
error
"getFileName(fAlias) --> " & fAlias & " does not exist."
end try
set o to
text item delimiters
set text item delimiters to ":"
--ensures that colon is
excluded
if (fAlias ends with ":") then
set fileStr to fAlias's text item
-2
else
set fileStr to fAlias's text item -1
end if
--reset TIDs to
original setting
set text item delimiters to o
return {pathname, fileStr}
end getFileName
on insertPie(docAlias, fileName, chartName)
try
set
docCode to (chartName's text from character -13 to character -15) & "PER-" &
dateCode
set finalDoc to ("" & destFolder & docCode)
set myPie to ("" &
imagePath & docCode & ".eps")
set myPie to (myPie as alias)
on error errMsg
number errNum
error "File does not exist."
end try
tell document 1 of
application "QuarkXPress(tm)"
activate
open docAlias
if not (document 1
exists) then
open docAlias
end if
tell picture box 1 of document 1
try
set image 1 to myPie
set bounds of image 1 to centered
on error
errMsg number errNum
set image 1 to (choose file with prompt "Select pie
chart:")
set bounds of image 1 to centered
end try
end tell
try
save document 1 in file finalDoc without template
on error errMsg number
errNum
tell application "Finder"
display dialog " Can't save document
due to error " & errNum & return & errMsg
end tell
end try
close
document 1 saving no
end tell
end insertPie
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.