Randomize colors

Source: Pixelmator Ninja


Apply some randomness to the fill or stroke color of selected objects.

  • Select several objects
  • Run script
  • Select fill or stroke
  • Choose amount of randomness (1 to 100)


use scripting additions

on new_number(old_number, a)
	set n to old_number + (random number from (0 - a * 655) to a * 655)
	if n < 0 then
        set n to 0
    end if
	if n > 65534 then
        set n to 65535
    end if
	return n
end new_number


tell application "Pixelmator Pro"
	activate
	tell its front document

		set scope to ¬
			(choose from list {"fill", "stroke"} with prompt "Fill or stroke?" default items {"fill"}) as text
		
        set a to text returned of ¬
			(display dialog "Amount (1..100):" default answer "5" buttons {"Cancel", "OK"} default button "OK")
		set a to a as number

		set selected_layers to selected layers
		repeat with l in selected_layers
			if (scope = "fill") then
				set current_color to the fill color of the styles of l
			else
				set current_color to the stroke color of the styles of l
			end if
			set new_r to my new_number(item 1 of current_color, a)
			set new_g to my new_number(item 2 of current_color, a)
			set new_b to my new_number(item 3 of current_color, a)
			tell styles of l
				if (scope = "fill") then
					set fill color to {new_r, new_g, new_b}
				else
					set stroke color to {new_r, new_g, new_b}
				end if
			end tell
		end repeat
	end tell
end tell

Download AppleScript file

Suggest an improvement  ·  How to install scripts