Examples of AppleScripts for applications

Open script: use document preferences

To open a document using document preferences, specify the following as a custom "open" script and enter "yes" for the first argument.

on run {args} 
  set theJobPath to infile of args 
  set theDocPrefs to arg1 of args 
  set scriptResult to "/OK/" 
  tell application "QuarkXPress" 
    try 
      if (theDocPrefs is equal to "yes") then 
        open alias theJobPath use doc prefs yes remap fonts no do auto picture import no 
      else 
        open alias theJobPath use doc prefs no remap fonts no do auto picture import no 
      end if 
    on error errmsg number errnum 
      set scriptResult to ("/ERROR/:" & errmsg) 
    end try 
  end tell 
  return scriptResult 
end run

Command script: reverse page order in a document

To reverse the page order in a document, specify the following as a custom "command" script. The script doesn't use any arguments.

on run {args} 
  set scriptResult to "/OK/" 
  tell application "QuarkXPress" 
    try 
      if not (exists document 1) then error "No open document" 
      tell document 1 
        set pageCnt to count of page 
        if pageCnt is not equal to 1 then 
          repeat with i from 1 to pageCnt 
            move page pageCnt to before page i 
          end repeat 
        end if 
      end tell 
    on error errmsg number errnum 
      set scriptResult to ("/ERROR/:" & errmsg) 
    end try 
  end tell 
  return scriptResult 
end run

Save as script: save as multi-file DCS

To save a document as multi-file DCS, specify the following as a custom "save as" script (using a compiled script). The script uses the first argument to specify the color setup ("Grayscale", "Composite RGB", "Composite CMYK", "Composite CMYK andSpot", "As Is").

on run {args} 
  set theOutputSetup to arg1 of args 
  set theResultJobPath to "/ERROR/:Unknown error" 
 
  using terms from application "PowerSwitch_Service" 
    tell application (server of args) 
      try 
        set theJob to jobobject of args 
        set theJobProper to proper name of theJob 
        set theResultJobPath to create path theJob name theJobProper with creating folder 
      on error errmsg number errnum 
        set theResultJobPath to ("/ERROR/:" & errmsg) 
        return theResultJobPath 
      end try 
    end tell 
  end using terms from 
 
  tell application "QuarkXPress" 
    try 
      if not (exists document 1) then error "No open document" 
      tell document 1 
        set pageCnt to count of pages 
        repeat with i from 1 to count of pages 
 
          -- Create the sequential number for the file 
          set fileNum to i 
          repeat until (length of (fileNum as text)) = (length of (pageCnt as text)) 
            set fileNum to "0" & fileNum 
          end repeat 
 
          set FileName to theJobProper & "_" & fileNum & ".eps" 
          set theResultPath to theResultJobPath & ":" & FileName 
 
          save page i in theResultPath EPS format Multiple File DCS EPS data binary EPS scale 100 Output Setup theOutputSetup with transparent page 
        end repeat 
      end tell 
      close document 1 without saving 
    on error errmsg number errnum 
      set theResultJobPath to ("/ERROR/:" & errmsg) 
    end try 
  end tell 
 
  return theResultJobPath 
end run