on run argv    
    if (count of argv) > 0 then
        set shapeType to item 1 of argv
        set textSize to item 2 of argv
        set textStyle to item 3 of argv
        set textColor to run script ("{" & item 4 of argv & "}") 
        set arrowColor to run script ("{" & item 5 of argv & "}") 
        set lineWeight to item 6 of argv
        set compoundFormat to item 7 of argv
        set dashFormat to item 8 of argv
        set lineColor to run script ("{" & item 9 of argv & "}") 
        set isNoFill to item 10 of argv
        set isSolidFill to item 11 of argv
        set isGradientFill to item 12 of argv
        set solidColor to run script ("{" & item 13 of argv & "}") 
        set solidTransparency to item 14 of argv
        set gradientType to item 15 of argv
        set gradientDirection to item 16 of argv
        set gradientAngle to item 17 of argv
        set stopData to my split(item 18 of argv, "*")
        set currentPosition to my split(item 19 of argv, ",")
        set fontName to item 20 of argv
        set isNoLine to item 21 of argv
    else
        error "Shape or Text properties are not provided"
    end if

    tell application "Microsoft PowerPoint"
        if (count of slide show windows) > 0 then
            set currentSlide to current show position of slide show view of item 1 of slide show windows
        else
            set currentSlide to slide number of slide range of selection of active window
        end if
    end tell
    
    if shapeType is "RECTANGLE" or shapeType is "RECTANGLE_ROUNDED" or shapeType is "CIRCLE" then
        my AddShapeProperties(currentSlide, shapeType, currentPosition, isNoLine, lineWeight, dashFormat, compoundFormat, lineColor, isNoFill, isSolidFill, isGradientFill, solidColor, solidTransparency, gradientType, gradientDirection, gradientAngle, stopData)

    else if shapeType is "ARROW" then
        my AddArrowProperties(currentSlide, currentPosition, arrowColor)

    else
        my AddTextProperties(currentSlide, currentPosition, textSize, textStyle, textColor, fontName)
    end if
    
end run

to AddTextProperties(currentSlide, currentPosition, textSize, textStyle, textColor, fontName)
    -- Add text properties
    tell application "Microsoft PowerPoint"
        set myDocument to slide currentSlide of active presentation
        set newText to make new text box at myDocument with properties {left position:item 1 of currentPosition, top: item 2 of currentPosition, width:100, height:100}

        -- Set content to text box
        tell text range of text frame of newText
            set content to "Text Box"
        end tell

        -- Set font properties
        tell font of text range of text frame of newText
            set font name to fontName
            set font size to textSize
            set font color to textColor
            set bold to textStyle contains "bold"
            set italic to textStyle contains "italic"
            set underline to textStyle contains "underline"
        end tell
    end tell
end AddTextProperties

to AddArrowProperties(currentSlide, currentPosition, arrowColor)
    -- Add arrow properties
    tell application "Microsoft PowerPoint"
        set myDocument to slide currentSlide of active presentation
        set newArrow to make new line shape at myDocument with properties {left position:100, top: item 1 of currentPosition, width:100, height:0}

        tell line format of newArrow
            set end arrowhead style to 3
            set fore color to arrowColor
        end tell
    end tell
end AddArrowProperties

to AddShapeProperties(currentSlide, shapeType, currentPosition, isNoLine, lineWeight, dashFormat, compoundFormat, lineColor, isNoFill, isSolidFill, isGradientFill, solidColor, solidTransparency, gradientType, gradientDirection, gradientAngle, stopData)
    -- Shape Types
    set msoShapeOval to 9
    set msoShapeRectangle to 1
    set msoShapeRoundedRectangle to 5

    -- 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 Shape Types
    set shapeValue to msoShapeRectangle -- Default
    if shapeType is "RECTANGLE" then
        set shapeValue to msoShapeRectangle
    else if shapeType is "RECTANGLE_ROUNDED" then
        set shapeValue to msoShapeRoundedRectangle
    else if shapeType is "CIRCLE" then
        set shapeValue to msoShapeOval
    end if

    -- 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
    
    -- Apply all settings in one tell block
    tell application "Microsoft PowerPoint"
        set myDocument to slide currentSlide of active presentation
        -- Create a new shape
        set newShape to make new shape at myDocument with properties {auto shape type:shapeValue, left position:item 1 of currentPosition, top:item 2 of currentPosition, width:100, height:100}

        -- Set line format
        tell line format of newShape
            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 newShape

            if isNoFill is "true" then
                set visible to false

            else if isSolidFill is "true" then
                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 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