Author Topic: Adding Drop Shadows in Quark  (Read 273 times)

0 Members and 1 Guest are viewing this topic.

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Adding Drop Shadows in Quark
« on: September 06, 2016, 08:56:10 AM »
I found a way to add drop shadows in Quark using AppleScript. However, I am struggling to get it to add drop shadows only to the images that don't already have one. The script is supposed to duplicate each image that is only in the document once, add a drop shadow to the duplicate image and resize the duplicate image to only .08 inches tall. The list of graphics that are in the document more than once appears to work correctly. I must be doing something wrong in the part after that. If anyone could help me figure out what I need to change, it would be greatly appreciated.


Code: [Select]
on open of droppedFiles --> This is the line of code that begins a droplet. 
with timeout of 900 seconds -->The script will try for 15 minutes before timing out. Default is 2 minutes, which is way too little.


-----------------------------------------------------------------------------------------
--BEGINNING REPEAT LOOP AND OPENING FILE
-----------------------------------------------------------------------------------------

repeat with afile in droppedFiles

tell application "QuarkXPress"
activate
open afile

-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------



-----------------------------------------------------------------------------------------
--UNLOCKING PAGE ITEMS JUST IN CASE SOMETHING WE WANT UNLOCKED WAS LOCKED
-----------------------------------------------------------------------------------------

tell document 1

set vertical measure to inches
set horizontal measure to inches

try
set format lock of every item to false
set content lock of every item to false
end try

-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------




-----------------------------------------------------------------------------------------
--BUILDING A LIST OF THE GRAPHICS THAT ARE IN THE DOCUMENT MORE THAN ONCE
-----------------------------------------------------------------------------------------

set originalList to {}

--Looping through every graphic to build a list that contains the name of every link
set theBoxes to every picture box
repeat with abox in theBoxes
set thepath to file path of image 1 of abox as string
set originalList to originalList & thepath
end repeat
--returns {AG654321.tif, AG123456.tif, AG123456.tif}

--------------------------

--Building two lists of every link that has at least 2 copies in the document
set list1 to {}
--display dialog aLinkName & "-" & matchCount
repeat with x from 1 to count of items of originalList
set n to item x of originalList
--if n is in list2 and n is not in doubleImageList then set end of doubleImageList to n
set matchCount to my count_matches(originalList, n)
if matchCount is greater than 1 then
set list1 to list1 & n
end if
end repeat
--returns {AG123456.tif, AG123456.tif}

set list2 to {}
repeat with x from 1 to count of items of originalList
set n to item x of originalList
set matchCount to my count_matches(originalList, n)
if matchCount is greater than 1 then
set list2 to list2 & n
end if
end repeat
--returns {AG123456.tif, AG123456.tif}

--------------------------

--Building final list which only contains the name of duplicate images once
set doubleImageList to {}
repeat with x from 1 to count of items of list1
set n to item x of list1
if n is in list2 and n is not in doubleImageList then set end of doubleImageList to n
end repeat
--returns {AG123456.tif}

-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------




-----------------------------------------------------------------------------------------
--LOCKING BOXES & GROUPS THAT ARE IN THE DOCUMENT MORE THAN ONCE
-----------------------------------------------------------------------------------------

--Locking all groups
select every group box
tell application "System Events" to key code 97 -->locking the group
set selection to null

--Creating a list of boxes that are only in the document once and a list of boxes that are in the document multiple times
set pictureBoxes to every picture box
set shadowedIDList to {}
set unshadowedIDList to {}
repeat with i from 1 to the number of pictureBoxes
set pictureBox to item i of pictureBoxes
set imagePath to file path of image 1 of pictureBox as string
if imagePath is in doubleImageList then
set shadowedIDList to shadowedIDList & uniqueID of pictureBox as string
else
set unshadowedIDList to unshadowedIDList & uniqueID of pictureBox as string
end if
end repeat


-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------




-----------------------------------------------------------------------------------------
--ADDING THE DROP SHADOWS TO BOXES THAT ARE ONLY IN THE DOCUMENT ONCE
-----------------------------------------------------------------------------------------

set shadowedBoxes to (every picture box whose uniqueID is in shadowedIDList)
set unshadowedBoxes to (every picture box whose uniqueID is in unshadowedIDList)


repeat with unshadowedBox in unshadowedBoxes

--Duplicating the picture box
set duplicateBox to duplicate unshadowedBox to after unshadowedBox
set duplicateImage to image 1 of duplicateBox


--Getting the bounds (coordinates) of the picture box
set y1 to coerce (item 1 of (bounds of unshadowedBox as list)) to real
set x1 to coerce (item 2 of (bounds of unshadowedBox as list)) to real
set y2 to coerce (item 3 of (bounds of unshadowedBox as list)) to real
set x2 to coerce (item 4 of (bounds of unshadowedBox as list)) to real


--Moving the top of the box down so it is only 0.08" high but the other coordinates are the same as the original box that was duplicated
set new_y1 to y2 - 0.08 as number
set content lock of duplicateImage to true
set bounds of duplicateBox to {new_y1, x1, y2, x2}


--Adding the drop shadow to the duplicated box
select duplicateBox
tell application "System Events" to key code 97 using {command down} -->Pressing Command F6 to activate the drop shadow item style
set selection to null

end repeat

-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------




-----------------------------------------------------------------------------------------
--SAVING & CLOSING THE DOCUMENTS
-----------------------------------------------------------------------------------------

close saving yes

-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------




end tell --end of tell document 1 block
end tell --end of tell Quark block
end repeat --end of first repeat loop
end timeout
end open --> This is the line of code that ends a droplet.

--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------

--HANDLER THAT COUNTS THE NUMBER OF TIMES AN ITEM IS IN THE LIST
on count_matches(this_list, this_item)
set the match_counter to 0
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then
set the match_counter to the match_counter + 1
end repeat
return the match_counter
end count_matches