We’re moving to InDesign and have the Markzware Q2ID plugin. I wrote this script that uses UI scripting to convert the quark files using Markzware and then it tells InDesign to do a few things with each file before saving. My only problem is that InDesign is trying to process the converted files BEFORE the Markzware plugin is done converting. I used a long delay to prevent that, but the time it takes to convert the files will vary depending on the number of files selected.
Is there a better way to get InDesign to wait for the plugin to finish before the script moves on to processing the open documents?
-----------------------------------------------------------------------------------------
--DISPLAYING A MESSAGE TO THE USER
tell application "SystemUIServer"
display dialog "This script is going to take a little while. You can move on to something else. It will display a message when done." with icon note
end tell
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--CHOOSING FILES TO CONVERT
my do_submenu("Adobe InDesign CC 2014", "Markzware", "Q2ID", "Convert QuarkXPress(c) Document...")
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--DELAYING THE SCRIPT 10 MINUTES TO GIVE THE CONVERTER TIME BEFORE THE INDESIGN PART RUNS
delay 600 -- delaying 10 minutes before processing files
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--GETTING RID OF ANNOYING POP UP BOXES IN INDESIGN
tell application "Adobe InDesign CC 2014"
activate
set user interaction level of script preferences to never interact -->Prevents InDesign from popping up warnings that interrupt the script.
tell view preferences
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--FITTING TEXT FRAMES TO THE CONTENT IF THERE IS AN OVERFLOW
--THIS WAY WE DON'T RISK HAVING CUT OFF TEXT IN AN AD
set allFiles to every document
repeat with afile in allFiles
tell document 1
set locked of every page item to false
--Looking through every text frame and fitting the frame to content if there is overset text
set everyTextFrame to every text frame
repeat with textFrame in everyTextFrame
if overflows of textFrame then
fit textFrame given frame to content
--set textFrameContents to stories of textFrame
--set horizontal scale of textFrameContents to "105"
--set horizontal scale of textFrameContents to "100"
end if
end repeat
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--SELECTIVELY MOVING TEXT BOXES TO THE FRONT
--BECAUSE THE TEXT HAS LINES THROUGH IT IF IS NOT BROUGHT TO THE FRONT
--Bringing each text frame to the front IF the fill color of that text frame is "None"
--It could mess up the layout if text boxes with a background color were brought to the front, so I added a condition to make sure that doesn't happen.
set theTextFrames to (every text frame whose name of fill color is "None")
bring to front theTextFrames
end tell
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--REMOVING _LAYOUT 1 FROM THE FILENAME
set oldDelims to AppleScript's text item delimiters
--ELIMINATING _LAYOUT 1 IN FILENAME
if name of afile contains "_Layout 1" then
set AppleScript's text item delimiters to {"_Layout 1"}
set fileName to name of afile --> ex. Disneyland.tif
set nameWithoutExtension to first text item of fileName --> Disneyland
set newName to nameWithoutExtension & ".indd" --> Disneyland_s_4c.tif
else
set AppleScript's text item delimiters to {""}
end if
--RESETTING APPLESCRIPT'S TEXT ITEM DELIMITERS
set AppleScript's text item delimiters to oldDelims
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--SAVING AND CLOSING THE DOCUMENT ON THE DESKTOP
set saveFolder to path to desktop as string
set savePath to saveFolder & newName
save active document to savePath
close active document
end repeat
end tell
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
--DISPLAYING A MESSAGE TO LET THE USER KNOW THIS IS DONE
tell application "SystemUIServer"
display dialog "The pages are converted and saved on your desktop!" with icon note
end tell
-----------------------------------------------------------------------------------------
--------------------------------------------
--The UI Scripting select submenu function
--Thanks to http://www.macosxautomation.com/applescript/uiscripting/
on do_submenu(app_name, menu_name, menu_item, submenu_item)
try
-- bring the target application to the front
tell application app_name
activate
end tell
tell application "System Events"
tell process app_name
tell menu bar 1
pick menu bar item menu_name
tell menu bar item menu_name
tell menu menu_name
pick menu item menu_item
tell menu item menu_item
tell menu menu_item
pick menu item submenu_item
click menu item submenu_item
end tell
end tell
end tell
end tell
end tell
end tell
end tell
return true
on error error_message
return false
end try
end do_submenu
AppleScript: AppleScript 2.2.1
Browser: Safari 537.78.2
Operating System: Mac OS X (10.7)