I am trying to update an OS 9 script for Quark to use in OS X. I think I have the general idea down, but I know I am missing a few details. This script is supposed to check for images that are out of the 85-100% range and drop them into a sub-folder to correct. I have it working to the point of getting the Quark files and opening, then closing. What I am having trouble with is getting the script to communicate to the Finder that a new folder needs to be created if the files are out of the range. I am also having trouble updating the syntax to get the scale of the images in picture boxes.
If anyone has a bit of guidance, I would really appreciate it.
thanks,
Levon
(**
This script does the following:
Open a folder and check the contents for Quark files
See if any art placed in picture boxes in Quark is less than 85% or greater than 100%
Close without saving
Place these items in a sub-folder to manually correct
**)
set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"qxd"} or kind contains "QuarkXPress" or file type is in {"XPRJ", "XPR3"}
repeat with oneFile in theFiles
tell application "QuarkXPress"
activate
open (oneFile as alias)
tell front document
set docName to name
repeat with i from 1 to count of picture boxes
try
set theScale to scale of image 1 of picture box i as list
set thisScale to (item 1 of theScale)
set imagePath to file path of image 1 of picture box i
set imageName to my pathName(imagePath)
if thisScale as real is less than "85" or thisScale as real is greater than "100" then
tell application "Finder"
(move oneFile to folder) make new folder at folderName with properties {name:"Incorrectly Scaled Files"}
end tell
display dialog "There are files out of scale range in the folder 'Incorrectly Scaled Files.' Please manually fix the files and then re-run this script."
end if
end try
end repeat
close saving no
end tell
end tell
end repeat
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)
Well, I started messing around with this and became obsessed with making it work. Here is what I came up with. I commented out a couple lines that you had that weren’t needed. I don’t know if you have other things planned that reference them. I also added an exit repeat once it finds one so you won’t have to wait for it to go through the whole document after it’s already found one. Hope this works for you!
set FileSample to choose folder
set path2ChosenFolder to FileSample as string
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"qxd"} or kind contains "QuarkXPress" or file type is in {"XPRJ", "XPR3"}
repeat with oneFile in theFiles
tell application "QuarkXPress"
activate
open (oneFile as alias) use doc prefs yes remap fonts no do auto picture import yes
tell front document
--set docName to name
repeat with i from 1 to count of picture boxes
--try
set thisScale to (item 1 of (scale of image 1 of picture box i as list)) as integer
--set imagePath to file path of image 1 of picture box i
--set imageName to my pathName(imagePath)
if thisScale is less than "85" or thisScale is greater than "100" then
tell application "Finder"
if not (exists folder (path2ChosenFolder & "Incorrectly Scaled Files")) then
make new folder at (path2ChosenFolder as alias) with properties {name:"Incorrectly Scaled Files"}
end if
move file (oneFile as alias) to (path2ChosenFolder & "Incorrectly Scaled Files") as alias
end tell
display dialog "There are files out of scale range in the folder 'Incorrectly Scaled Files.' Please manually fix the files and then re-run this script."
exit repeat
end if
--end try
end repeat
close saving no
end tell
end tell
end repeat
Model: G5
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Here is a script that I can’t remember where I got this from so my apologies to the author. If you do a collect for output from Quark including images, you can then open up the collected Quark Doc use “Break picture links” XT the Quark file will then relink to the collected images where you can run this:
property min_scaling : 90
property max_scaling : 110
-- images information from QuarkXPress
try
tell application "QuarkXPress" to tell document 1
set _file_pathes to (file path of images)
if class of _file_pathes is not list then ¬
set _file_pathes to coerce _file_pathes to list
set _scales to (scale of images) as list
if class of item 1 of _scales is not list then ¬
set _scales to {{item 1 of _scales, item 2 of _scales}}
end tell
on error
display dialog "Error occured!" & return & return ¬
& "Open QuarkXPress document first and" & return ¬
& "update all pictures in it." buttons {"OK"} default button 1 with icon stop
return
end try
-- information analysing “ list of bad scaling images
set BAD_scaling_images to {}
repeat with i from 1 to length of _scales
tell application "QuarkXPress"
set {y_scale, x_scale} to (item i of _scales)
set x_scale to x_scale as real
set y_scale to y_scale as real
end tell
try
tell application "Finder" to ¬
set creator_type to creator type of item i of _file_pathes
on error
set creator_type to ""
end try
if ((x_scale < min_scaling or x_scale > max_scaling) or ¬
(y_scale < min_scaling or y_scale > max_scaling)) and ¬
creator_type is "8BIM" then ¬
set end of BAD_scaling_images to {(item i of _file_pathes), i, x_scale, y_scale}
end repeat
set action_name to text returned of ¬
(display dialog "If You wish, You may enter action name" & return ¬
& "for applying to proccesing images." default answer "" buttons {"OK"} default button 1 with icon note)
if action_name is not "" then ¬
set action_set to text returned of ¬
(display dialog "Please, enter name of action set of action" & return ¬
& "'" & action_name & "'" default answer "" buttons {"OK"} default button 1 with icon note)
--resampling bad scaling files
repeat with i from 1 to length of BAD_scaling_images
set image_file to item 1 of (item i of BAD_scaling_images)
set x_scale to item 3 of (item i of BAD_scaling_images)
set y_scale to item 4 of (item i of BAD_scaling_images)
tell application "Adobe Photoshop CS2"
activate
open image_file
tell current document
set _resolution to resolution
set _width to width * x_scale / 100
set _height to height * y_scale / 100
resize image width _width ¬
height _height ¬
resolution _resolution ¬
resample method bicubic
try
do action action_name from action_set
end try
close saving yes
end tell
end tell
end repeat
--end of work
tell application "QuarkXPress"
activate
repeat with i from 1 to length of BAD_scaling_images
set image_index to item 2 of (item i of BAD_scaling_images)
tell document 1 to ¬
set scale of image image_index to {100, 100}
end repeat
display dialog ((length of BAD_scaling_images) as string) & " images are resampled." & return ¬
& "Now You must update all images" & return ¬
& "and set it's correct position." buttons {"Cool!.."} default button 1 with icon note
end tell
Matt,
I can see why you made the changes you did. I am a bit unfamiliar with some of the syntax, but it looks like it should work. When I run it, I get the error “Can’t make «data FX% 00010000» into type integer.” If I cut out the “as integer” line I get a “Can’t make «data FX% 00010000» into type number, date or text.” error. I am using Quark XPress 6.5 btw, if it makes a difference. I think that moving the files will be a bit easier than understanding why the script can not get the scale of a picture box for me.
thanks,
Levon
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)
Mark,
When I try this one, I get a “Can’t make «data FX% 0000CCCD» into type real.” error. Is this something I am doing wrong on my end, or maybe version conflicts? I am running Adobe CS2 and Quark XPress 6.5 in 10.4.8.
thanks,
Levon
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)
Weird. I just tested it again with files that have scaled graphics that get moved to the subfolder, as well as files with no picture boxes or empty boxes, and I am not able to reproduce your error message.
I am also in 10.4 using Quark 6.5. I’m not sure what else to check. Anyone else have any ideas??
Model: G5
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Sprale, I very much suspect that you are running an intel mac a lot of «data FX% 0000CCCD» errors are down to not having your script and application both running under rosetta. I don’t have one of these but you need to do a comm+i and set to run under emulator or something to that effect (im sure others here can give you better guidance to that.) Yuo may well need to do this with your editor too.
Mark,
I am actually running a Dual 2.3 G5, so I am not sure where the errors could be coming from. I am going to rewrite parts of the script to separate bits into different steps instead of trying to do it all at once. I will let everyone know how it goes.
thanks,
Levon
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger4
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)
I am debugging the script right now and run into values being returned that don’t read right to me. When I get to the “set thisScale to (item 1 of theScale)” line, I get “scale of image 1 of picture box 1 of picture box 1 of document 1 of picture box 1 of document 1 of application “QuarkXPress”” returned as a value.
This is the point where I am erroring out right now. Setting this value does not make sense to me. When I call up this line in “if thisScale as real is less than “85” or thisScale as real is greater than “100” then” I get “Can’t make «class pscl» of «class IMAG» 1 of «class PICB» 1 of «class PICB» 1 of document 1 of «class PICB» 1 of document 1 of application “QuarkXPress” into type real.” returned as a value and the error stops the script.
Here is the current script, v4.2.2:
set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"qxd"} or kind contains "QuarkXPress" or file type is in {"XPRJ", "XPR3"}
repeat with oneFile in theFiles
tell application "QuarkXPress"
activate
open (oneFile as alias)
tell front document
--set the current view scale of this document to fit in window
set view scale to 100
--set docName to name
repeat with i from (count of picture boxes) to 1 by -1
tell picture box i
set theScale to scale of image 1 of picture box i as list
set thisScale to (item 1 of theScale)
--set imagePath to file path of image 1 of picture box i
--set imageName to my pathName(imagePath)
if thisScale as real is less than "85" or thisScale as real is greater than "100" then
tell application "Finder"
--Does folder exist? -No
make new folder at folder folderPATH with properties {name:"Incorrectly Scaled Files"}
--If not, then create it
move oneFile to folder "Incorrectly Scaled Files"
--Move files that are out of range to the folder
end tell
display dialog "There are files out of scale range in the folder 'Incorrectly Scaled Files.' Please manually fix the files and then re-run this script."
end if
end tell
end repeat
close saving no
end tell
end tell
end repeat
Let me know what you think, maybe where I am using incorrect syntax causing this oddly formatted result to be returned.
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)