Couldn't think of a better title. Too many questions.
WORKFLOW
BACKGROUND
As a webdeveloper you highly likely find yourself using classic background colors as you build complex layouts. The color won't stay for long, so it has to be typed fast. It doesn't make sense to add variables of a beautiful debugging color pallet.. so you write `background: red`, `background: yellow` – But these colors just look awful. CSS has many many other names you could remember.. (https://www.w3schools.com/colors/colors_names.asp) I can't –
WORKFLOW
PURPOSE
"Alt+Space" > "csc" > Look > CMD+5 > "LightBlueSky" gets pasted right into active application.
WHAT I HAVE
SO FAR (php workflow with workflows.php)
– I chose my favorite colors and put them in an associative Array
– I (want to) shuffle the array so you don't forcefully fall in love with colors 1-3
– You can filter the colors by their name (Woop Woop!)
– dynamicIcon.php that creates an square image as preview for the color
– Activating an item pastes it to active app and doesn't polute the clipboard-history (Thanks, Alfred!)
Obviously it doesn't go as smooth as I wish it to. So here are the two main issues I am facing:
1) dynamicIcon.php successfully creates an image, when accessed via a browser, but as a parameter in "$wf->result()" shows me the finger!
2) Shuffling the assoc-array works in a conventional webdev-environment, but again, Alfred shows me the finger on this one!
Both issues probably no-brainers for advanced workflowers (:D) and veterans– I guess the icon-parameter needs a path (string) pointing to an actual image; so .. I need to save / cache the image created by dynamicIcon.php somewhere?
Why-No-Shuffle is a complete mystery to me.
Here is the beautiful lady:
https://www.dropbox.com/s/sfm7kh1c6hh70oc/Colorfull Alpha.alfredworkflow?dl=0
Or if you want to see the code here:
Scriptfilter:
//
// Load the PHP workflow library.
include_once("workflows.php");
//
// Create the workflow object to use.
$wf = new Workflows();
//
// Get the raw query and store it for use.
$clean = trim("{query}");
//
// Set the colors
$colors = array(
"DarkSlateBlue" => "483D8B",
"RoyalBlue" => "4169E1",
"RebeccaPurple" => "663399",
"LightSkyBlue" => "87CEFA",
"PaleGreen" => "98FB98",
"Sienna" => "A52A2A",
"GreenYellow" => "ADFF2F",
"RosyBrown" => "8C8F8F",
"DarkKhaki" => "BDB76B",
"Silver" => "C0C0C0",
"MediumVioletRed" => "C71585",
"Chocolate" => "D2691E",
"Peru" => "CD853F",
"Orchid" => "DA70D6",
"Plum" => "DDA0DD",
"Gainsboro" => "DCDCDC",
"Lavender" => "E6E6FA",
"DarkSalmon" => "E9967A",
"LightCoral" => "F08080"
);
//
// Shuffle assoc array
function shuffle_assoc($my_array) {
$keys = array_keys($my_array);
shuffle($keys);
foreach($keys as $key) {
$new[$key] = $my_array[$key];
}
$my_array = $new;
return $my_array;
}
$shuffled_colors = shuffle_assoc($colors);
//
// Build items
foreach ($shuffled_colors as $title => $hex) {
$reg = '/(.*){query}(.*)/i';
if (!empty("{query}") && !preg_match($reg, $title)) continue;
$wf->result($title, $title, $title, $hex, "dynamicIcon.php?hex=" . $hex, "yes");
}
//
// Alfred workflow.php magic producing the items, I guess?
echo $wf->toxml();
dynamicIcon.php
header("Content-type: image/png");
$hex = "#" . ltrim($_GET["hex"], "#"); // to make with or without hash valid parameter;
list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
$im = @imagecreate(64,64) or die("cannot initialize new GD image stream");
$backgroundColor = imagecolorallocate($im, $r, $g, $b);
imagepng($im);
imagedestroy($im);
Thanks!
Louis
PS: Name and keyword definitely not final;