on run argv
    if (count of argv) > 0 then
        set isNoLine to item 1 of argv
        set lineWeight to item 2 of argv
        set compoundFormat to item 3 of argv
        set dashFormat to item 4 of argv
        set lineColor to run script ("{" & item 5 of argv & "}")
        set isNoFill to item 6 of argv
        set isSolidFill to item 7 of argv
        set isGradientFill to item 8 of argv
        set solidColor to run script ("{" & item 9 of argv & "}")
        set solidTransparency to (item 10 of argv / 100)
        set gradientType to item 11 of argv
        set gradientDirection to item 12 of argv
        set gradientAngle to item 13 of argv
        set stopData to my split(item 14 of argv, "*")
    else
        error "Shape properties are not provided"
    end if

    tell application "Microsoft PowerPoint"
        if (count of slide show windows) > 0 then
            -- Run when in presentation mode
            error "PowerPoint is in presentation mode. Cannot perform operation." number 60002
        else
           my AddShapeProperties(isNoLine, lineWeight, dashFormat, compoundFormat, lineColor, isNoFill, isSolidFill, isGradientFill, solidColor, solidTransparency, gradientType, gradientDirection, gradientAngle, stopData)
        end if
    end tell
end run

to AddShapeProperties(isNoLine, lineWeight, dashFormat, compoundFormat, lineColor, isNoFill, isSolidFill, isGradientFill, solidColor, solidTransparency, gradientType, gradientDirection, gradientAngle, stopData)
    -- Dash Styles
    set msoLineSolid to 1
    set msoLineSquareDot to 10
    set msoLineRoundDot to 11
    set msoLineDash to 4
    set msoLineDashDot to 5
    set msoLineLongDash to 7
    set msoLineLongDashDot to 8
    set msoLineDashDotDot to 6
    set msoLineLongDashDotDot to 9
    
    -- Compound Styles
    set msoLineSingle to 1
    set msoLineThinThin to 2
    set msoLineThinThick to 3
    set msoLineThickThin to 4
    set msoLineThickBetweenThin to 5

    -- Precompute Dash and Compound Styles
    set dashValue to msoLineSolid -- Default
    if dashFormat is "square_dot" then
        set dashValue to msoLineSquareDot
    else if dashFormat is "round_dot" then
        set dashValue to msoLineRoundDot
    else if dashFormat is "dash" then
        set dashValue to msoLineDash
    else if dashFormat is "dash_dot" then
        set dashValue to msoLineDashDot
    else if dashFormat is "long_dash" then
        set dashValue to msoLineLongDash
    else if dashFormat is "long_dash_dot" then
        set dashValue to msoLineLongDashDot
    else if dashFormat is "long_dash_dot_dot" then
        set dashValue to msoLineLongDashDotDot
    end if

    set compoundValue to msoLineSingle -- Default
    if compoundFormat is "thin_thin" then
        set compoundValue to msoLineThinThin
    else if compoundFormat is "thin_thick" then
        set compoundValue to msoLineThinThick
    else if compoundFormat is "thick_thin" then
        set compoundValue to msoLineThickThin
    else if compoundFormat is "thick_between_thin" then
        set compoundValue to msoLineThickBetweenThin
    end if

    tell application "Microsoft PowerPoint"
        -- Get selected shapes
        set theShapeRange to shape range of selection of active window
        set shapeCount to (count of shapes of theShapeRange)
        -- Apply properties to each shape
        repeat with i from 1 to shapeCount
            -- Set line format
            tell line format of shape i of theShapeRange
                if isNoLine is "true" then
                    set transparency to 1.0
                else
                    set transparency to 0
                    -- Set line weight only if provided
                    if lineWeight is not "" then
                        set line weight to lineWeight
                    end if
                    -- Apply dash and compound styles
                    set dash style to dashValue
                    set line style to compoundValue
                end if
                -- Set line color
                set fore color to lineColor
            end tell

            -- Set fill format
            tell fill format of shape i of theShapeRange
                if isNoFill is "true" then
                    set visible to false

                else if isSolidFill is "true" then
                    set back color to solidColor
                    set fore color to solidColor                
                    set transparency to solidTransparency

                else if isGradientFill is "true" then
                    -- LINEAR
                    if gradientType is "LINEAR" then
                        if gradientDirection is "tlbr" then
                            one color gradient style 3 variant 1 degree 1
                        else if gradientDirection is "bltr" then
                            one color gradient style 4 variant 2 degree 1               
                        else if gradientDirection is "trbl" then
                            one color gradient style 4 variant 1 degree 1
                        else if gradientDirection is "brtl" then
                            one color gradient style 3 variant 2 degree 1                    
                        else if gradientDirection is "ld" then
                            one color gradient style 1 variant 1 degree 1                  
                        else if gradientDirection is "lu" then
                            one color gradient style 1 variant 2 degree 1  
                        else if gradientDirection is "lr" then
                            one color gradient style 2 variant 1 degree 1                   
                        else if gradientDirection is "ll" then
                            one color gradient style 2 variant 2 degree 1        
                        else if gradientDirection is "custom" then
                            one color gradient style 1 variant 1 degree 1
                        end if

                    -- RETANGULAR    
                    else if gradientType is "RETANGULAR" then
                        if gradientDirection is "fbr" then
                            one color gradient style 5 variant 4 degree 1                        
                        else if gradientDirection is "fbl" then
                            one color gradient style 5 variant 3 degree 1                        
                        else if gradientDirection is "fc" then
                            one color gradient style 7 variant 1 degree 1                        
                        else if gradientDirection is "ftr" then
                            one color gradient style 5 variant 2 degree 1                        
                        else if gradientDirection is "ftl" then
                            one color gradient style 5 variant 1 degree 1
                        end if

                    -- PATH    
                    else if gradientType is "PATH" then
                        one color gradient style 7 variant 1 degree 1                    
                    end if 
                    -- Set gradient stops
                    repeat with index from 1 to count of stopData
                        if item index of stopData contains "-" then
                            set stopValue to item index of stopData
                            set oldDelimiters to AppleScript's text item delimiters
                            set AppleScript's text item delimiters to "-"
                            set stopPros to text items of stopValue
                            set AppleScript's text item delimiters to oldDelimiters

                            if (count of stopPros) > 0 then
                                set stopColor to run script ("{" & item 1 of stopPros & "}")
                                set stopPosition to (item 2 of stopPros) / 100
                                set stopTransparency to (item 3 of stopPros) / 100

                                -- Insert gradient stop only if index is greater than 2
                                if index > 2 then
                                    insert gradient stop custom color stopColor position stopPosition transparency stopTransparency
                                else
                                    set color of gradient stop index to stopColor
                                    set position of gradient stop index to stopPosition
                                    set transparency of gradient stop index to stopTransparency
                                end if
                            end if
                        end if
                    end repeat
                end if
            end tell
        end repeat

    end tell  

    
end AddShapeProperties

to split(someText, delimiter)
    set oldDelimiters to AppleScript's text item delimiters
    set AppleScript's text item delimiters to delimiter
    set myList to text items of someText
    set AppleScript's text item delimiters to oldDelimiters
    return myList
end split