Scripting Layer Opacity change

Hello!
I want to create a script that decreases current layer opacity by 5. Here's what I have now:
app.activeDocument.activeLayer.opacity -= 5;
The problem is, when I map the script to a hotkey and press it multiple times (e.g. to set opacity to 50%), it goes normal from 100 to 95, from 95 to 90 and so on until 75%. From that point, it goes to 69% (should be 70%). Then it proceeds as it should (69 -> 64, 64 -> 59).
It also breaks at 24% (24 -> 18), if that matters.
I use Adobe Photoshop CS6 on Windows 8.1 (x64).
Why is this happening (decrease by 6 when I have 5 in my code)? Am I doing something wrong? Sorry if this question is stupid, I am just new to Photoshop scripting...

ahawktom,
opacity is not a rounded value and opacity works with percent.
Try something like this:
if (app.activeDocument.activeLayer.opacity > 5) {
    app.activeDocument.activeLayer.opacity = Math.round(app.activeDocument.activeLayer.opacity) -5;
Have fun

Similar Messages

  • Layer opacity shortcut

    Are able Layer opacity change through shortcut?
    Thanks!

    Your question is very terse, but insofar as you can assign a shortcut key to an action or script, and an action can do just about anything you can do, then the short answer is yes.
    If  you do choose to create an action to help you manage layer opacity, you'll have to make some assumptions about the document you're working on, and the conditions in which you're working.  An action can't really make decisions - for example it can't take one of two paths of execution based on whether the layer is an adjustment layer or an image layer.  A script, by contrast, can do conditional execution.
    With something as simple as current layer opacity, an action should be able to affect a variety of different kinds of layers, so assuming you want a shortcut key to set the current layer to a fixed level of opacity - e.g., 50% - I'd try the action approach first.
    Hope this helps.
    -Noel

  • When using the Save Layer Comps to PDF Script, can you change the PDF settings. I need both Smallest File Size and Press Quality?

    When using the Save Layer Comps to PDF Script, can you change the PDF settings. I need both Smallest File Size and Press Quality? Thanks in advance to the group for assisting with this matter.
    — John

    No, there isn't. The way you're using the file is not recommended. You
    should use a review tracker to avoid getting in the way of one another.

  • Changing Layer Opacity in an Action

    An action that I created uses and preserves adjustment layers. The action will not recognize the changes In opacity that I've made to the layers. How can I get the action to record the opacity changes?

    Actually it should record that with no problem.
    The step should appear as »Set current layer« (see attachment).
    Please explain in more detail how you created the Action: Did you for example change opacity immediately after layer creation and how (via keyboard shortcut or slider), do you work with a non english version of Photoshop?

  • How can I prevent pixelization during opacity change?

    I am creating a small WMV ( 197x148 ) which includes a static image and a video clip. I am encountering 2 problems:
    Video has a pixelated edge
    Video opacity change is pixelated, and not smooth
    Any help appreciated - what surprised me is that during the fast preview they look fine, but when they render they get janky. Is there a dithering option I need to disable or somesuch?!
    Thanks in Advance!!!

    Thanks - I tried to include my timeline large enough to read in the second image.
    I adjusted the layer blending property under LAYER -> BLENDING MODE -> NORMAL and this resolved my issue!
    Thanks so much!

  • Layer Opacity percentage from Photoshop is different in After Effects

    When importing a layered PS CS3 document into AE CS3 with layers set to different opacity, AE interprets the % differently. AE displays the % as a whole number but when you click on the field you can see the number goes to at least the thousandths.
    This is an issue as our animators need to usually make footage loop perfectly and if they use the default imported value as the start value, and then change it over time and then create a new keyframe at the end of the loop to the whole number it displays, it is actually different so there is a slight shift.
    As you can see in this example:
    PS layer opacity = 10%
    AE layer opacity = 10.196%
    PS layer opacity = 20%
    AE layer opacity = 20%
    PS layer opacity = 30%
    AE layer opacity = 30.196%
    PS layer opacity = 40%
    AE layer opacity = 40%
    PS layer opacity = 22%
    AE layer opacity = 21.0968%
    PS layer opacity = 88%
    AE layer opacity = 87.8431%
    Anyone else know why this is happening? This is a mind boggler for me.
    Thanks,
    Jon
    FYI, our Macs are running:
    OS X 10.5.4
    AE CS3 8.0.2.27
    PS CS3 10.0.1

    Simple: AE will use a higher precision than Photoshop even in the 8bpc/16bpc modes, let alone 32bpc. Photoshop will surely use the same values internally, but it doesn't display them. Dunno why, but PS being the old dog it is, I'm not really wondering... More of a question for that forum for sure. Could of course also be a problem with different color profiles/ color space settings between the apps, so this might be worth checking. Maybe you are using an outdated version of a profile in one of them... A simple solution inside AE would be to simply nail down those values with expressions, e.g.
    opacity.valueAtTime(thisComp.startTime)
    Otherwise: Stay away from the evil Photoshop. ;-)
    Mylenium

  • [solved]script fails when changing profile through powerdevil.

    i use ondemand governor and i want to change up_threshold value.
    Whenever i change profile through powerdevil up_threshold gets its default vaule of 80.
    what i did was to create a script named threshold containing the lines:
    #!/bin/bash
    sudo sh -c 'echo 50 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold'
    i have also set through /etc/sudoers that this script is passwordless for my user.
    if i run the script, it successfully changes the value. It also runs successfully if i put it in startup.
    My problem is that it fails to run when i choose it to run when a profile loads through powerdevil. I am refering to the feature shown below :
    at first i thought that this function has a problem. so i chose to run kate, and when i changed profile, kate started immediately. So i guess that there is a problem with my script.
    Any ideas?
    Last edited by mechmg93 (2009-10-20 20:14:30)

    I hope someone reads this thread also its already marked as solved...
    Anyway, i would like to use CPU frequency scaling, but in the powermanagement settings,
    i cant shoose anything for frequency scaling.
    What do i have to do to be able to set "ondemand" or "always lowest frequency"?
    Wich daemons and/or modules do i have to activate to change the frequency policy?
    Would be very nice if someone could help me.

  • FCP won't display opacity changes (fades or keyframed opacity changes)

    So I've been fighting with FCP for a couple days now. 11 hours of rendering last night and it's no good. Wherever there's a fade or a keyframed opacity change, it simply displays black, or sometimes, the track under the affected track.
    I have deleted the render files, and that didn't help. I then completely removed and re-installed FCP and no luck. Any suggestions?
    Thanks

    try FCP Rescue
    Trashes preferences. pretty straight forward.
    Shane

  • How to change the angle of a gradient layer without changing anything else?

    How to change the angle of a gradient layer without changing anything else?
    When I try it myself my whole gradient turns black.

    To add to the above, you can not just set the angle. If you want to use other existing settings you need to get them from the layer. The code in that other thread shows one way to get them.
    But if you do not need the existing values for any other reason you can get the descriptor for the layer, make a duplicate of it with all the settings and just overwrite the ones you want to change.
    This is one way to just change the angle while keeping the other existing settings.
    // helper function for working with descriptors
    function getProperty( psClass, psKey, index ){// integer:Class, integer:key
        var ref = new ActionReference();
        if( psKey != undefined ) ref.putProperty( charIDToTypeID( "Prpr" ), psKey );
        if(index != undefined ){
            ref.putIndex( psClass, index );
        }else{
            ref.putEnumerated( psClass , charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
        try{
            var desc = executeActionGet(ref);
        }catch(e){ return; }// return on error
        if(desc.count == 0) return;// return undefined if property doesn't exists
        var dataType = desc.getType(psKey);
        switch(dataType){// not all types supported - returns undefined if not supported
            case DescValueType.INTEGERTYPE:
                return desc.getInteger(psKey);
                break;
            case DescValueType.ALIASTYPE:
                return desc.getPath(psKey);
                break;
            case DescValueType.BOOLEANTYPE:
                return desc.getBoolean(psKey);
                break;
            case DescValueType.BOOLEANTYPE:
                return desc.getBoolean(psKey);
                break;
            case DescValueType.UNITDOUBLE:
                return desc.getUnitDoubleValue(psKey);
                break;
            case DescValueType.STRINGTYPE:
                return desc.getString(psKey);
                break;
            case  DescValueType.OBJECTTYPE:
                return desc.getObjectValue(psKey);
                break;
            case  DescValueType.LISTTYPE:
                return desc.getList(psKey);
                break;
            case  DescValueType.ENUMERATEDTYPE:
                return desc.getEnumerationValue(psKey);
                break;
    function duplicateDescriptor( descriptor ) {
        var newDescriptor = new ActionDescriptor;
        newDescriptor.fromStream( descriptor.toStream() );
        return newDescriptor;
    function localizeDescriptor( desc ) {
        var stream, pointer, zStringLength, zstring, localized_string, newZStringLength, previousStream, followingStream, newDesc;
        stream = desc.toStream();
        while( true ) {
            pointer = stream.search(/TEXT....\x00\$\x00\$\x00\$/);
            if( pointer === -1 ) {
                break;
            zStringLength = getLongFromStream( stream, pointer + 4 );
            zstring = readUnicode( stream.substr( pointer + 8, ( zStringLength - 1 ) * 2) );
            localized_string = ( localize( zstring ) ) + '\u0000';
            newZStringLength = localized_string.length;
            previousStream = stream.slice( 0, pointer);
            followingStream = stream.slice( pointer + 8 + zStringLength * 2);
            stream = previousStream.concat( 'TEXT', longToString( newZStringLength ), bytesToUnicode( localized_string ), followingStream );
        newDesc = new ActionDescriptor();
        newDesc.fromStream( stream );
        return newDesc;
    function getShortFromStream( stream, pointer ) {
        var hi, low;
        hi = stream.charCodeAt( pointer ) << 8 ;
        low = stream.charCodeAt( pointer + 1 );
        return hi + low;
    function getLongFromStream( stream, pointer ) {
        var hi, low;
        hi = getShortFromStream( stream, pointer) << 16;
        low = getShortFromStream( stream, pointer + 2);
        return hi + low;
    function readUnicode( unicode ) {
        var string = "";
        for( i = pointer = 0; pointer < unicode.length; i = pointer += 2) {
            string +=String.fromCharCode( getShortFromStream( unicode, pointer ) );
        return string;
    function longToString( longInteger ) {
        var string;
        string = String.fromCharCode( longInteger >>> 24 );
        string += String.fromCharCode( longInteger << 8 >>> 24 );
        string += String.fromCharCode( longInteger << 16 >>> 24 );
        string += String.fromCharCode( longInteger << 24 >>> 24 );
        return string;
    function bytesToUnicode( bytes ) {
        var unicode = "", char_code, charIndex;
        for( charIndex  = 0; charIndex < bytes.length; charIndex ++ ) {
            char_code = bytes.charCodeAt( charIndex );
            unicode += String.fromCharCode(char_code >> 8 ) +  String.fromCharCode( char_code & 0xff );
        return unicode;
    function setGradientAdjustmentAngle( angle ) {
        var adjustmentDesc = getProperty( charIDToTypeID("Lyr "), charIDToTypeID( 'Adjs' ) ).getObjectValue(0);
        var newAdjustmentDesc = duplicateDescriptor( adjustmentDesc );
        newAdjustmentDesc.putUnitDouble( charIDToTypeID('Angl'), charIDToTypeID('#Ang'), angle );
        var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putEnumerated( stringIDToTypeID('contentLayer'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
        desc.putReference( charIDToTypeID('null'), ref );
        desc.putObject( charIDToTypeID('T   '), stringIDToTypeID('gradientLayer'), newAdjustmentDesc);
        executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
    var newAngle = 45;
    setGradientAdjustmentAngle( newAngle );

  • Why do vector lines appear different in my Photoshop document compared to the PDF that was created using "Scripts Layer Comps to PDF"? And how do I get them to look the same?

    Why do vector lines appear different in my Photoshop document compared to the PDF that was created using "Scripts > Layer Comps to PDF"? And how do I get them to look the same?

    BOILERPLATE TEXT:
    If you give complete and detailed information about your setup and the issue at hand, such as your platform (Mac or Win), exact versions of your OS, of Photoshop and of Bridge, machine specs, what troubleshooting steps you have taken so far, what error message(s) you receive, if having issues opening raw files also the exact camera make and model that generated them, etc., someone may be able to help you.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • Script for printing changed pages only

    Does anyone know of a script that will allow the printing of only those pages that have had changes made to them since a previous save? I'm a typesetter doing work only on books and journals and sometimes it's a bit tedious to keep track of the individual pages one works on. thanks,

    Ok,
    Here is a raw code. All you need to do is edit the script to specify the printer preset you want to use. I don't have a printer my self to debug but I think it should work.
    Here is the idml to grab the object styles. Don't forget to apply on objects located onto the pasteboard. The script look for these objects and grab the page name next to them to finally print these pages.
    Hope it helps,
    Loic
    function main(){
              var doc,
              changedArray = [],
              changedStyle,
              unchangedStyle,
              i=0,
              max=0,
              found = [],
              pagerange = [];
              obj,
              vb,
              leftPage,
              leftPageBounds,
              rightPage,
              rightPageBounds,
              pagerange = "";
              if(!app.documents.length){ return; }
              var doc = app.activeDocument;
              changedStyle = doc.objectStyles.itemByName("changed");
              unchangedStyle = doc.objectStyles.itemByName("unchanged");
              if(!changedStyle.isValid ||  !changedStyle.isValid){
                        alert("Problem with object styles. Script requires both \"changed\" and \"unchanged\" styles.");
                        return;
              app.findObjectPreferences.appliedObjectStyles = changedStyle;
              found = doc.findObject();
              max = found.length;
              for(i=0; i<max; i++){
                        obj = found[i];
                        vb = obj.visibleBounds;
                        leftPage = obj.parent.pages[0];
                        leftPageBounds = leftPage.bounds;
                        rightPage = obj.parent.pages[-1];
                        rightPageBounds = rightPage.bounds;
                        if(vb[1]>rightPageBounds[1]){
                                  pagerange.push(rightPage.name);
                        else if(vb[1]<leftPageBounds[1]){
                                  pagerange.push(leftPage.name);
              app.printPreferences.activePrinterPreset = app.printerPresets.itemByName("my printer preset");
              var oldPrintPrefs = doc.printPreferences.pageRange;
              doc.printPreferences.pageRange = pagerange.join(",");
              alert("Gone printing");
              app.print();
              doc.printPreferences.pageRange = oldPrintPrefs;
    main();

  • CS 6 layer opacity issue

    In the middle of working on a file my layer opacity started acting weird. If I reduce the opacity to 90% it looks like I have dropped it by 60%. This happened on the file i was working on but when I opened a new file and filled a box with solid black (100%) and then duplicated the layer and reduced that one to 90% it looked fine. SO I thought I had a memory issue. I quit PS then I restarted. Now no matter what file I open or create, my opacity is not proportional to the slider. 90% looks like 60% of any layer I make. Now, when I save the file and place it in an InDesign document, the preview looks as it should. What gives? There are no adjustment layers or layer masks apllied to the layers.
    You can see the large discrepency in shade from 100% black to 90% black.
    Please help. Its driving me nuts!

    Charles,
    Thanks for your reply but I discovered the problem. Gamut warning! I inadvertently must have hit shift-command-Y and unchecked the Gamut Warning under the View menu.
    Here is the opacity in RGB mode with the gamut warning UNCHECKED:
    And with the gamut warning CHECKED:
    I knew it was just me hitting some random setting that screwed it up. User error as usual. Not sure why the gamut warning needs a keyboard shortcut, but whatever.

  • How to save png from psd that preserves transparency of 85% FILL opacity & 100% Layer opacity?

    I am using PS CS3. My design has a shiny colored glass type effect with 100% layer opacity, but an 85% fill opacity so that you can see through it. I have tried everything to save as a png file that preserves the transparency but nothing works. Thanks for any help!

    Thank you both for your help and questions.
    I am using several effects including bevel and emboss, inner shadow, inner glow, satin, etc. If I lower the layer opacity then everything is affected and I want my highlights, etc. to stay crisp and still be able to see through the object as if it were colored glass.
    I did finally figure out how to get it to do what I wanted. I lowered my fill opacity to 0% and added a color overlay at 65% opacity. This got me the exact look and transparency that I wanted when I saved as a png.
    Thanks again.

  • Script help -- to change the path of some script

    hi
    is it possible to make a script(perl or shell) which will change the location of sql script those are called from different shell script?
    i have some shell script which is calling some sql scripts.now i need one script which will ask for the path of those script once and set the path of those sql script in those shell script.these shell script only containing a line
    "sqlplus / as sysdba @<path of the sql script>/script.sql" now i need one script which will change <path of the sql script> .is it possible to do ??
    i need some help from gurus ...
    rgrds
    Edited by: new2appsdba on Aug 20, 2010 7:16 PM

    Hi
    can you say how to pass this mpath to n number of shell script??
    i need to update n number of script.ie. i need to pass $mpath variable to n number of script.
    example:
    profile_chk.sh contain only :
    sqlplus apps/<pass> @/u02/uatdb/.DBA-Scripts/profile_chk.sqlprofile_chk.sql contain:
    SELECT A.PROFILE_OPTION_ID,A.LEVEL_ID,A.LEVEL_VALUE,A.PROFILE_OPTION_VALUE,V.USER_PROFILE_OPTION_NAME
    FROM APPS.FND_PROFILE_OPTION_VALUES A, APPS.FND_PROFILE_OPTIONS_VL V
    WHERE A.PROFILE_OPTION_ID =V.PROFILE_OPTION_ID
    AND V.USER_PROFILE_OPTION_NAME like '%Debug Log%';
    select t.user_profile_option_name, profile_option_value
    from apps.fnd_profile_options o
    ,apps.fnd_profile_option_values v
    ,apps.fnd_profile_options_tl t
    where o.profile_option_id = v.profile_option_id
    and o.application_id = v.application_id
    and profile_option_value = 'Y'
    and start_date_active = SYSDATE
    and o.profile_option_name = t.profile_option_name
    and level_id=10001
    and (upper(t.user_profile_option_name) like '%PERSONALIZ%'
    and upper(t.user_profile_option_name) not like '%PERSONALIZ%WYSIWYG%'
    order by user_profile_option_name;
    select t.user_profile_option_name, profile_option_value, application_name
    from apps.fnd_profile_options o
    ,apps.fnd_profile_option_values v
    ,apps.fnd_profile_options_tl t
    ,apps.fnd_application_tl a
    where o.profile_option_id = v.profile_option_id
    and o.application_id = v.application_id
    and profile_option_value = 'Y'
    and start_date_active = SYSDATE
    and o.profile_option_name = t.profile_option_name
    and a.application_id = level_value
    and level_id=10002
    and t.language = a.language
    and upper(t.user_profile_option_name) like '%PERSONALIZ%'
    order by user_profile_option_name, application_name;now i need a script say install.sh
    which will update the location of profile_chk.sql in the profile_chk.sh.
    this install.sh will contain n numbers of
    install -c profile_chk.sh /usr/bin so that all user can access this shell script as a command.
    whenever the testing goes one server contains two instance so each everytime i need to monitor locks and invalid objects and etc so i need to use this scripts as a commands.for that reason i need this install -c for each scripts.and i need to visit different places also.so ineed this install.sh.my idea is basically work properly once and enjoy times lazily :-) so whenever i move to new place i shall only run this install.sh once and use those scripts lazily.
    rgrds

  • Layer Opacity

    Can layer opacity be adjusted on PS Touch?

    Found the answer and it is "Yes". At bottom left of layer window .. tap on papers icon.

Maybe you are looking for