RE: Newbie Quark Scripting critique
RE: Newbie Quark Scripting critique
- Subject: RE: Newbie Quark Scripting critique
- From: Hans Haesler <email@hidden>
- Date: Thu, 24 Oct 2002 13:04:25 +0200
On Wed, 23 Oct 2002, Wallace, William wrote:
>
My first question is: Is there an easier, more elegant way to get the path
>
to the chosen file (excluding the actual filename)?
Bill,
Shane has shown you an easier way. Here is a similar but shorter one.
It doesn't use 'thePath' and there is a slight difference when setting
'pathToFile' (okay, the work for the script is the same).
Important: it includes a filter for the file type. With 'choose file of
type "XDOC"' the user sees only QuarkXPress documents (and not image
and text files and invisible stuff...)
Another remark: don't use the Finder for testing if the EPS folder
exists. This is faster: put '(pathToFile & "EPSfiles:") as alias' in
a try wrapper. If the folder exists then all is well, else -- and only
then -- the Finder is asked to make the folder. BTW, I have to use
'...make new folder at folder pathToFile...'. Without the second 'folder'
I get an error (using Mac OS 9.2.1). In my version, below, the variable
'outFolder' is set before the existing-folder test. This way you can use
this shorter form: 'outFolder as alias'.
And: instead of counting the pages and using this value in the final
dialog, I think it is better to increment a counter inside of the try
wrapper. Else the script might return a wrong number.
>
Second question: I seem to recall there being a debate about nesting Tell
>
blocks like I have them. Was any consensus reached? Is this bad form? Am I
>
playing with fire here?
Not at all :-). Below I have inserted a 'tell document 1' block. This way
you don't need to repeat 'of document 1'.
---
tell application "QuarkXPress(tm) 4.11"
activate
set theFile to (choose file of type "XDOC" with prompt "Pick a file.") as string
set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set pathToFile to (text 1 thru text item -2 of theFile) & ":"
set AppleScript's text item delimiters to oldTIDs
set outFolder to pathToFile & "EPSfiles:"
try
outFolder as alias
on error
tell application "Finder" to make new folder at folder pathToFile with properties {name:"EPSfiles"}
end try
open theFile use doc prefs yes remap fonts no
set ctr to 0
tell document 1
set docName to name
repeat with i from 1 to count of pages
set outFile to outFolder & docName & i & ".eps"
try
save page i in outFile EPS format Mac color EPS data binary EPS
set ctr to ctr + 1
end try
end repeat
end tell
close document 1 saving no
display dialog "I have generated " & ctr & " EPS files for you." buttons "OK" default button 1 with icon 1
end tell
---
I have also added 'EPS format Mac color EPS data binary EPS'. The resulting
files _look_ the same. But there must be a difference because the count
of the bytes is different. I don't know if this is important.
---
Hans Haesler <email@hidden>
_______________________________________________
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.