Kater Louis Posted September 23, 2017 Share Posted September 23, 2017 (edited) 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; Edited September 23, 2017 by Kater Louis Link to comment
deanishe Posted September 23, 2017 Share Posted September 23, 2017 53 minutes ago, Kater Louis said: dynamicIcon.php successfully creates an image, when accessed via a browser Well yeah. Because it’s a web script that only understands input sent by a browser (URL query strings via $_GET) and sends output only a browser would understand (HTTP headers). Alfred isn’t a browser, so scripts written for webservers and HTTP won’t work. If you want to generate images and view them in Alfred, you need to save them to files and pass Alfred the filepaths. Link to comment
Kater Louis Posted September 25, 2017 Author Share Posted September 25, 2017 On 23. September 2017 at 3:58 PM, deanishe said: If you want to generate images and view them in Alfred, you need to save them to files and pass Alfred the filepaths. Yeah, I figured something like that– What is the common approach for this? The workflow "colors" needs dynamic images aswell. I can't imagine the workflow has saved a square for each and every color there is And any idea on the shuffle issue? Thanks! Link to comment
deanishe Posted September 25, 2017 Share Posted September 25, 2017 1 hour ago, Kater Louis said: Yeah, I figured something like that– What is the common approach for this? The way you’re using it, rewrite the script to be a function that saves the generated files to your workflow’s cache directory (workflow.php should be able to provide the path). 1 hour ago, Kater Louis said: The workflow "colors" needs dynamic images aswell. I can't imagine the workflow has saved a square for each and every color there is I would assume it generates the images as needed when you enter a specific colour. That’s the sensible way to do it. 1 hour ago, Kater Louis said: And any idea on the shuffle issue? Afraid not. PHP really isn’t my thing. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now