Tips & Tricks Part 3: Add CMYK Color

Discuss AppleScripting for QuarkXPress 2015, 2016 & 2017.

Tips & Tricks Part 3: Add CMYK Color

Postby pjanssen » 30 Nov 2016, 08:43

I created some Applescripts, which might be useful for others too. So I wanted to share them here.

The third one is for adding a CMYK color with a name composed out of the CMYK values.

Code: Select all
set ColorCheck to false
tell application "QuarkXPress"
   if exists document 1 then
      activate
      set DefaultAnswer to "0 0 0 0"
      repeat until ColorCheck is true
         set NewColor to text returned of (display dialog "New Color (C M Y K): " default answer DefaultAnswer)
         set ColorValueList to words of NewColor
         set ColorValueNumber to count items of ColorValueList
         set ColorCheck to true
         if ColorValueNumber = 4 then
            set ColorValueCyan to item 1 of ColorValueList as number
            set ColorValueMagenta to item 2 of ColorValueList as number
            set ColorValueYellow to item 3 of ColorValueList as number
            set ColorValueBlack to item 4 of ColorValueList as number
            if ColorValueBlack < 0 or ColorValueBlack > 100 then
               set ColorCheck to false
               set ErrorDialog to "Black isn't between 0 and 100!"
               set DefaultAnswer to NewColor
            end if
            if ColorValueYellow < 0 or ColorValueYellow > 100 then
               set ColorCheck to false
               set ErrorDialog to "Yellow isn't between 0 and 100!"
               set DefaultAnswer to NewColor
            end if
            if ColorValueMagenta < 0 or ColorValueMagenta > 100 then
               set ColorCheck to false
               set ErrorDialog to "Magenta isn't between 0 and 100!"
               set DefaultAnswer to NewColor
            end if
            if ColorValueCyan < 0 or ColorValueCyan > 100 then
               set ColorCheck to false
               set ErrorDialog to "Cyan isn't between 0 and 100!"
               set DefaultAnswer to NewColor
            end if
         else
            set ColorCheck to false
            set ErrorDialog to "Four color values need to be entered!"
            set DefaultAnswer to NewColor
         end if
         if ColorCheck is false then
            display dialog ErrorDialog buttons {"OK", "Cancel"}
         end if
      end repeat
      set ColorName to "C" & ColorValueCyan & " M" & ColorValueMagenta & " Y" & ColorValueYellow & " K" & ColorValueBlack
      set QXPColorValueCyan to (ColorValueCyan * 655.35) div 1
      set QXPColorValueMagenta to (ColorValueMagenta * 655.35) div 1
      set QXPColorValueYellow to (ColorValueYellow * 655.35) div 1
      set QXPColorValueBlack to (ColorValueBlack * 655.35) div 1
      try
         tell document 1
            if not (exists color spec ColorName) then
               make new color spec at beginning with properties {class:color spec, color type:CMYK type, angle:"45", CMYK color value:{QXPColorValueCyan, QXPColorValueMagenta, QXPColorValueYellow, QXPColorValueBlack}, name:ColorName, separation:true}
            end if
         end tell
      end try
   end if
end tell


If you own Keyboard Maestro: more useful macros can be found here: http://forums.quark.com/viewtopic.php?f=17&t=28981
pjanssen
 
Posts: 130
Joined: 31 Dec 1969, 19:00

Return to QuarkXPress 20xx: Scripting

Who is online

Users browsing this forum: No registered users and 1 guest