Skip to content

Instantly share code, notes, and snippets.

@timpulver
Created November 8, 2013 11:23
Show Gist options
  • Save timpulver/7369676 to your computer and use it in GitHub Desktop.
Save timpulver/7369676 to your computer and use it in GitHub Desktop.
[AppleScript, InDesign CS6] Hex Color Paste – Script for Adobe InDesign CS6, which converts a hex color like "A107E6" to Red: 161, Green: 7, Blue: 230 and pastes the values in the color fields.

HexColorPaste for Adobe InDesign CS6

How to use

  • Open Terminal and run chflags nohidden ~/Library to show your library folder in Finder
  • Run killall Finder to close all Finder windows, so we can actually see the folder
  • Navigate to ~/Finder/Scripts
  • Download InDesignCS6_HexColorPaste.scpt and copy it to `~/Library/Scripts``
  • Download FastScripts, a freeware to run AppleScripts using shortcuts from here
  • Install, Start and go to Preferences
  • Navigate to /Users/yourname/Library/Scripts, there you should find the downloaded script
  • On the right you can create a shortcut to launch the script
  • Now copy a hexcode to the clipboard, i.e. 00AAFF
  • In InDesign CS6, create a new color if you want
  • Now double click on the color you want to paste the hex code in Image1 Image2
  • The text cursor should be left in the name field
  • Run the script by using the newly created shortcut
  • The hex-color should be filled in now...
-- Powder
-- v. 1.0
-- Applescript for InDesign (CS6).
-- Converts hex codes to decimal values and fills them
-- in the forms in InDesign's color menu
-- Usage:
-- 1) Copy a hexcode to the clipboard like "A100FF"
-- Copy a colour hex-code like
-- 2) (optional) Create a new color
-- 3) Double click the color you want to edit
-- 4) Run the script, it fill convert the hex code to
-- individual decimal values and fill them in for you.
-- The text cursor needs to be in the textfield "color name"
set hex_code to the clipboard
set hex_code_length to length of hex_code
if hex_code_length is not equal to 6 then
log "No valid hex-code in clipboard – " & hex_code
-- TODO: check if string is a real hex code –> [0-9A-F]
return
end if
set r_hex to ((characters 1 thru 2 of hex_code) as string)
set r_dec to fromHex(r_hex)
set g_hex to ((characters 3 thru 4 of hex_code) as string)
set g_dec to fromHex(g_hex)
set b_hex to ((characters 5 thru 6 of hex_code) as string)
set b_dec to fromHex(b_hex)
tell application "System Events"
tell process "InDesign"
set frontmost to true
keystroke tab
keystroke r_dec
keystroke tab
keystroke g_dec
keystroke tab
keystroke b_dec
keystroke tab
delay 1
keystroke return
end tell
end tell
-- fromHex function by David Livesay
on fromHex(str)
set n to 0
set i to 1
repeat with a in reverse of every text item of str
if a is greater than 9 or a is less than 0 then
set a to ASCII number of a
if a is greater than 70 then
set a to a - 87
else
set a to a - 55
end if
end if
set n to n + a * i
set i to i * 16
end repeat
return n
end fromHex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment