Last active
October 27, 2016 12:59
-
-
Save ebsaral/4408664 to your computer and use it in GitHub Desktop.
Brightness and Contrast adjustment in InDesign CS4 [MAC]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Author : Emin Bugra Saral | |
-- Author Website : http://www.eminbugrasaral.com | |
-- Sources : http://www.adobe.com/products/indesign/scripting/pdfs/InDesignCS4_ScriptingGuide_AS.pdf | |
-- Purpose : Changing brightness and contrast of an image in InDesign CS4 by using Photoshop CS4 | |
-- Warning: Please be sure you read "readme.txt" | |
tell application "Adobe InDesign CS4" | |
activate | |
-- default values : | |
set defaultBValue to 80 | |
set defaultCValue to 0 | |
set defaultSaveValue to false | |
-- create dialog | |
set adjuster to make dialog | |
tell adjuster | |
-- title | |
set name to "Brightness and Contrast settings for Photoshop CS4" | |
set myColumn to make dialog column | |
tell myColumn | |
-- bordered area, asking for values | |
set myBorder to make border panel | |
tell myBorder | |
make static text with properties {static label:"Brightness Level % "} | |
set brightnessLevel to make integer editbox with properties {edit value:defaultBValue} | |
make static text with properties {static label:"Contrast Level % "} | |
set contrastLevel to make integer editbox with properties {edit value:defaultCValue} | |
end tell | |
-- unbordered area, asking before saving | |
set saving to make checkbox control with properties {static label:"Ask me before saving", checked state:defaultSaveValue} | |
-- showing limits | |
make static text with properties {static label:""} | |
make static text with properties {static label:"Brightness must be between -150 and 150"} | |
make static text with properties {static label:"Contrast must be between -50 and 100"} | |
end tell | |
end tell | |
-- InDesign - Photoshop controlling | |
if selection = {} then | |
-- if nothing is selected | |
display dialog "You did NOT select anything!" with icon 0 | |
else if class of item 1 of selection is in {rectangle, oval, polygon} or class of item 1 of selection is in {image, PDF, EPS} then | |
-- checking if the image is directly selected or not | |
if class of item 1 of selection is in {rectangle, oval, polygon} then -- frame | |
set imageLink to item link of graphic 1 of selection | |
set imagePath to file path of item link of graphic 1 of selection | |
else if class of item 1 of selection is in {image, PDF, EPS} then -- directly | |
set imageLink to item link of item 1 of selection | |
set imagePath to file path of item link of item 1 of selection | |
end if | |
-- myStatus holds for controlling input errors, to continue the while loop | |
set myStatus to true | |
repeat while myStatus is true | |
set showAdjuster to show adjuster | |
-- if user pressed OK | |
if showAdjuster is true then | |
-- saving result check to define parameter will be used in PS CS4 | |
if checked state of saving is true then | |
set savingParam to ask | |
else | |
set savingParam to yes | |
end if | |
-- initialize error message | |
set errorMsg to null | |
-- define variables from inputs which will be used in PS CS4 | |
set theBrightness to edit value of brightnessLevel | |
set theContrast to edit value of contrastLevel | |
-- some logic statements | |
if theBrightness is 0 and theContrast is 0 then | |
set myStatus to false | |
destroy adjuster | |
else if theBrightness > 150 then | |
set errorMsg to "Brightness Level cannot be greater than 150" | |
set edit value of brightnessLevel to 150 | |
else if theBrightness < -150 then | |
set errorMsg to "Brightness Level cannot be less than -150" | |
set edit value of brightnessLevel to -150 | |
else if theContrast > 100 then | |
set errorMsg to "Contrast Level cannot be greater than 100" | |
set edit value of contrastLevel to 100 | |
else if theContrast < -50 then | |
set errorMsg to "Contrast Level cannot be less than -50" | |
set edit value of contrastLevel to -50 | |
else | |
-- stop while loop and open PS CS4 | |
set myStatus to false | |
destroy adjuster | |
tell application "Adobe Photoshop CS4" | |
activate | |
open file imagePath | |
-- adjustment function with parameters taken above | |
adjust current layer of the current document using brightness and contrast with options {class:brightness and contrast, brightness level:theBrightness, contrast level:theContrast} | |
-- saving with the parameter taken above | |
close document 1 saving savingParam | |
end tell | |
-- time to pass on InDesign CS4 | |
tell application "Adobe InDesign CS4" | |
activate | |
-- refresh the image | |
relink imageLink to file imagePath | |
end tell | |
end if | |
-- if there was any error in logic, show it to the user | |
if errorMsg is not null then | |
display dialog errorMsg with icon 0 | |
end if | |
else | |
-- if the user pressed CANCEL, destroy everything and stop while loop | |
destroy adjuster | |
set myStatus to false | |
end if | |
end repeat | |
else | |
-- if the selected thing is neither an image's frame nor image | |
display dialog "Please select an image frame!" with icon 0 | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment