├── CONTRIBUTING.md ├── Hash.alfredworkflow ├── LICENSE ├── README.md ├── current-version.json ├── screenshots ├── alfred.png ├── hash.png └── sha.png └── src ├── hash.php ├── icon.png ├── update.json └── workflows.php /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | First off, thanks for you interest in contributing. Everyone who uses this repos really appreciates it. 3 | 4 | ![alt text][alfred] 5 | 6 | ## Issues 7 | All are welcome. 8 | 9 | ## Pull Requests 10 | Good pull requests - patches, improvements, new features - are a fantastic help. 11 | They should remain focused in scope and avoid containing unrelated commits. If 12 | your contribution involves a significant amount of work or substantial changes 13 | to any part of the project, please open an issue to discuss it first. 14 | 15 | Make sure to adhere to the coding conventions used throughout a project 16 | (indentation, accurate comments, etc.). Please update any documentation that is 17 | relevant to the change you're making. 18 | 19 | ## Pull Request Checklist 20 | Before you submit your PR please make sure everything is in order. 21 | 22 | - [ ] Installed `.alfredworkflow` file from repo before making changes. 23 | - [ ] Update the version in the workflow title. Double-click the workflow to edit. 24 | - [ ] Increase the version number in `update.json`. Right-click the workflow in Alfred, click `Show in Finder`. The `update.json` file will be in that folder. 25 | 26 | - [ ] Increase the version number in `current-version.json`. 27 | - [ ] If needed include a large icon in the `src/icon-src/` folder that has square dimensions. 28 | - [ ] If needed include a cached icon in the `sec/icon-cache/` folder that 256x256 pixels. Alfred creates these when you insert an image into a workflow. You can get this from inside the `.alfredworkflow`. Right-click the workflow in Alfred, click `Show in Finder`. The `--hash-value--.png` file will be in that folder. Copy to `/src/icon-cache` and rename. 29 | - [ ] If needed add a screenshot. Use ⌘ (command) + ⇧ (shift) + 4, press ␣ (space), then click on the Alfred window to create a clean screen shot. Place in the `screenshots` folder. 30 | - [ ] Update README.md with new version and any additional screenshots. 31 | - [ ] Export workflow to repo folder. Right-click the workflow in Alfred, click `Export...`. Don't include the `(v1.0)` in the name. 32 | 33 | ## Pull Request Process 34 | Please follow this process; it's the best way to get your work included in the 35 | project: 36 | 37 | 1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork, 38 | and configure the remotes: 39 | 40 | ```bash 41 | # Clones your fork of the repo into the current directory in terminal 42 | git clone https://github.com//.git 43 | # Navigate to the newly cloned directory 44 | cd 45 | # Assigns the original repo to a remote called "upstream" 46 | git remote add upstream https://github.com//.git 47 | ``` 48 | 49 | 2. If you cloned a while ago, get the latest changes from upstream: 50 | 51 | ```bash 52 | git checkout master 53 | git pull upstream master 54 | ``` 55 | 56 | 3. Create a new topic branch to contain your feature, change, or fix: 57 | 58 | ```bash 59 | git checkout -b 60 | ``` 61 | 62 | 4. Commit your changes in logical chunks. Please adhere to these [git commit 63 | message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) 64 | or your pull request is unlikely be merged into the main project. Use git's 65 | [interactive rebase](https://help.github.com/articles/interactive-rebase) 66 | feature to tidy up your commits before making them public. 67 | 68 | 5. Locally merge (or rebase) the upstream development branch into your topic 69 | branch: 70 | 71 | ```bash 72 | git pull [--rebase] upstream master 73 | ``` 74 | 75 | 6. Push your topic branch up to your fork: 76 | 77 | ```bash 78 | git push origin 79 | ``` 80 | 81 | 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests) 82 | with a clear title and description. 83 | 84 | [alfred]: ./screenshots/alfred.png "Alfred Workflow" 85 | -------------------------------------------------------------------------------- /Hash.alfredworkflow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willfarrell/alfred-hash-workflow/cfdda06eb384a334f5d687c1b559be08aab997f3/Hash.alfredworkflow -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 will Farrell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Hash ([Download v1.5](https://raw.github.com/willfarrell/alfred-hash-workflow/master/Hash.alfredworkflow)) 2 | ===================== 3 | 4 | hashing Strings. 5 | 6 | ## Requirements 7 | 1. [Alfred App v2](http://www.alfredapp.com/#download) 8 | 1. [Alfred Powerpack](https://buy.alfredapp.com/) 9 | 10 | ## Installing 11 | 1. Click the download buttons below 12 | 2. Double-click to import into Alfred 2 13 | 3. Review the workflow to add custom Hotkeys 14 | 15 | ## Updating 16 | Run the [Alleyoop Workflow](http://www.alfredforum.com/topic/1582-alleyoop-update-alfred-workflows/) using the keyword `oop`. If you're not comfortable with Alleyoop, **star & watch this repo** to keep up to date on new versions and additional workflows. 17 | 18 | ## About 19 | Hashes strings with algorithms like md5, sha1, sha512, and many others. 20 | 21 | ![alt text][hash] 22 | ![alt text][sha] 23 | 24 | ## Commands 25 | - `hash {query}` - hash query over all supported algorithms 26 | - `hash {algorithm} {query}` - hash query over all selected algorithm 27 | - `{md5,sha1,sha512} {query} - hash query over all selected algorithm 28 | 29 | Press enter to save hash to clipboard. 30 | 31 | ## Contributors 32 | - [@willfarrell](https://github.com/willfarrell) 33 | 34 | [hash]: ./screenshots/hash.png "Hash" 35 | [sha]: ./screenshots/sha.png "SHA" -------------------------------------------------------------------------------- /current-version.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1.3, 3 | "download_url": "https://raw.github.com/willfarrell/alfred-hash-workflow/master/Hash.alfredworkflow", 4 | "description": "Hashing Strings" 5 | } -------------------------------------------------------------------------------- /screenshots/alfred.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willfarrell/alfred-hash-workflow/cfdda06eb384a334f5d687c1b559be08aab997f3/screenshots/alfred.png -------------------------------------------------------------------------------- /screenshots/hash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willfarrell/alfred-hash-workflow/cfdda06eb384a334f5d687c1b559be08aab997f3/screenshots/hash.png -------------------------------------------------------------------------------- /screenshots/sha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willfarrell/alfred-hash-workflow/cfdda06eb384a334f5d687c1b559be08aab997f3/screenshots/sha.png -------------------------------------------------------------------------------- /src/hash.php: -------------------------------------------------------------------------------- 1 | result( "hash-$algo", $hash, "$algo", $hash, 'icon.png', 'yes' ); 31 | } 32 | } 33 | 34 | } 35 | 36 | if ( count( $w->results() ) == 0 ) { 37 | foreach($algos as $algo) { 38 | if (in_array($algo, $password_algos)) { 39 | $hash = password_hash($query, $algo); 40 | } else { 41 | $hash = hash($algo, $query); 42 | } 43 | $w->result( "hash-$algo", $hash, "$algo", $hash, 'icon.png', 'yes' ); 44 | } 45 | //$w->result( 'hash', $query, 'None', $query, 'icon.png', 'yes' ); 46 | } 47 | 48 | echo $w->toxml(); 49 | // **************** 50 | ?> -------------------------------------------------------------------------------- /src/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willfarrell/alfred-hash-workflow/cfdda06eb384a334f5d687c1b559be08aab997f3/src/icon.png -------------------------------------------------------------------------------- /src/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1.2, 3 | "remote_json": "https://raw.github.com/willfarrell/alfred-hash-workflow/master/current-version.json" 4 | } -------------------------------------------------------------------------------- /src/workflows.php: -------------------------------------------------------------------------------- 1 | path = exec('pwd'); 31 | $this->home = exec('printf $HOME'); 32 | 33 | if ( file_exists( 'info.plist' ) ): 34 | $this->bundle = $this->get( 'bundleid', 'info.plist' ); 35 | endif; 36 | 37 | if ( !is_null( $bundleid ) ): 38 | $this->bundle = $bundleid; 39 | endif; 40 | 41 | $this->cache = getenv('alfred_workflow_cache'); 42 | $this->data = getenv('alfred_workflow_data'); 43 | 44 | if ( !file_exists( $this->cache ) ): 45 | exec("mkdir '".$this->cache."'"); 46 | endif; 47 | 48 | if ( !file_exists( $this->data ) ): 49 | exec("mkdir '".$this->data."'"); 50 | endif; 51 | 52 | $this->results = array(); 53 | } 54 | 55 | /** 56 | * Description: 57 | * Accepts no parameter and returns the value of the bundle id for the current workflow. 58 | * If no value is available, then false is returned. 59 | * 60 | * @param none 61 | * @return false if not available, bundle id value if available. 62 | */ 63 | public function bundle() 64 | { 65 | if ( is_null( $this->bundle ) ): 66 | return false; 67 | else: 68 | return $this->bundle; 69 | endif; 70 | } 71 | 72 | /** 73 | * Description: 74 | * Accepts no parameter and returns the value of the path to the cache directory for your 75 | * workflow if it is available. Returns false if the value isn't available. 76 | * 77 | * @param none 78 | * @return false if not available, path to the cache directory for your workflow if available. 79 | */ 80 | public function cache() 81 | { 82 | if ( is_null( $this->bundle ) ): 83 | return false; 84 | else: 85 | if ( is_null( $this->cache ) ): 86 | return false; 87 | else: 88 | return $this->cache; 89 | endif; 90 | endif; 91 | } 92 | 93 | /** 94 | * Description: 95 | * Accepts no parameter and returns the value of the path to the storage directory for your 96 | * workflow if it is available. Returns false if the value isn't available. 97 | * 98 | * @param none 99 | * @return false if not available, path to the storage directory for your workflow if available. 100 | */ 101 | public function data() 102 | { 103 | if ( is_null( $this->bundle ) ): 104 | return false; 105 | else: 106 | if ( is_null( $this->data ) ): 107 | return false; 108 | else: 109 | return $this->data; 110 | endif; 111 | endif; 112 | } 113 | 114 | /** 115 | * Description: 116 | * Accepts no parameter and returns the value of the path to the current directory for your 117 | * workflow if it is available. Returns false if the value isn't available. 118 | * 119 | * @param none 120 | * @return false if not available, path to the current directory for your workflow if available. 121 | */ 122 | public function path() 123 | { 124 | if ( is_null( $this->path ) ): 125 | return false; 126 | else: 127 | return $this->path; 128 | endif; 129 | } 130 | 131 | /** 132 | * Description: 133 | * Accepts no parameter and returns the value of the home path for the current user 134 | * Returns false if the value isn't available. 135 | * 136 | * @param none 137 | * @return false if not available, home path for the current user if available. 138 | */ 139 | public function home() 140 | { 141 | if ( is_null( $this->home ) ): 142 | return false; 143 | else: 144 | return $this->home; 145 | endif; 146 | } 147 | 148 | /** 149 | * Description: 150 | * Returns an array of available result items 151 | * 152 | * @param none 153 | * @return array - list of result items 154 | */ 155 | public function results() 156 | { 157 | return $this->results; 158 | } 159 | 160 | /** 161 | * Description: 162 | * Convert an associative array into XML format 163 | * 164 | * @param $a - An associative array to convert 165 | * @param $format - format of data being passed (json or array), defaults to array 166 | * @return - XML string representation of the array 167 | */ 168 | public function toxml( $a=null, $format='array' ) { 169 | 170 | if ( $format == 'json' ): 171 | $a = json_decode( $a, TRUE ); 172 | endif; 173 | 174 | if ( is_null( $a ) && !empty( $this->results ) ): 175 | $a = $this->results; 176 | elseif ( is_null( $a ) && empty( $this->results ) ): 177 | return false; 178 | endif; 179 | 180 | $items = new SimpleXMLElement(""); // Create new XML element 181 | 182 | foreach( $a as $b ): // Lop through each object in the array 183 | $c = $items->addChild( 'item' ); // Add a new 'item' element for each object 184 | $c_keys = array_keys( $b ); // Grab all the keys for that item 185 | foreach( $c_keys as $key ): // For each of those keys 186 | if ( $key == 'uid' ): 187 | $c->addAttribute( 'uid', $b[$key] ); 188 | elseif ( $key == 'arg' ): 189 | $c->addAttribute( 'arg', $b[$key] ); 190 | elseif ( $key == 'type' ): 191 | $c->addAttribute( 'type', $b[$key] ); 192 | elseif ( $key == 'valid' ): 193 | if ( $b[$key] == 'yes' || $b[$key] == 'no' ): 194 | $c->addAttribute( 'valid', $b[$key] ); 195 | endif; 196 | elseif ( $key == 'autocomplete' ): 197 | $c->addAttribute( 'autocomplete', $b[$key] ); 198 | elseif ( $key == 'icon' ): 199 | if ( substr( $b[$key], 0, 9 ) == 'fileicon:' ): 200 | $val = substr( $b[$key], 9 ); 201 | $c->$key = $val; 202 | $c->$key->addAttribute( 'type', 'fileicon' ); 203 | elseif ( substr( $b[$key], 0, 9 ) == 'filetype:' ): 204 | $val = substr( $b[$key], 9 ); 205 | $c->$key = $val; 206 | $c->$key->addAttribute( 'type', 'filetype' ); 207 | else: 208 | $c->$key = $b[$key]; 209 | endif; 210 | else: 211 | $c->$key = $b[$key]; 212 | endif; 213 | endforeach; 214 | endforeach; 215 | 216 | return $items->asXML(); // Return XML string representation of the array 217 | 218 | } 219 | 220 | /** 221 | * Description: 222 | * Remove all items from an associative array that do not have a value 223 | * 224 | * @param $a - Associative array 225 | * @return bool 226 | */ 227 | private function empty_filter( $a ) { 228 | if ( $a == '' || $a == null ): // if $a is empty or null 229 | return false; // return false, else, return true 230 | else: 231 | return true; 232 | endif; 233 | } 234 | 235 | /** 236 | * Description: 237 | * Save values to a specified plist. If the first parameter is an associative 238 | * array, then the second parameter becomes the plist file to save to. If the 239 | * first parameter is string, then it is assumed that the first parameter is 240 | * the label, the second parameter is the value, and the third parameter is 241 | * the plist file to save the data to. 242 | * 243 | * @param $a - associative array of values to save 244 | * @param $b - the value of the setting 245 | * @param $c - the plist to save the values into 246 | * @return string - execution output 247 | */ 248 | public function set( $a=null, $b=null, $c=null ) 249 | { 250 | if ( is_array( $a ) ): 251 | if ( file_exists( $b ) ): 252 | if ( file_exists( $this->path.'/'.$b ) ): 253 | $b = $this->path.'/'.$b; 254 | endif; 255 | elseif ( file_exists( $this->data."/".$b ) ): 256 | $b = $this->data."/".$b; 257 | elseif ( file_exists( $this->cache."/".$b ) ): 258 | $b = $this->cache."/".$b; 259 | else: 260 | $b = $this->data."/".$b; 261 | endif; 262 | else: 263 | if ( file_exists( $c ) ): 264 | if ( file_exists( $this->path.'/'.$c ) ): 265 | $c = $this->path.'/'.$c; 266 | endif; 267 | elseif ( file_exists( $this->data."/".$c ) ): 268 | $c = $this->data."/".$c; 269 | elseif ( file_exists( $this->cache."/".$c ) ): 270 | $c = $this->cache."/".$c; 271 | else: 272 | $c = $this->data."/".$c; 273 | endif; 274 | endif; 275 | 276 | if ( is_array( $a ) ): 277 | foreach( $a as $k => $v ): 278 | exec( 'defaults write "'. $b .'" '. $k .' "'. $v .'"'); 279 | endforeach; 280 | else: 281 | exec( 'defaults write "'. $c .'" '. $a .' "'. $b .'"'); 282 | endif; 283 | } 284 | 285 | /** 286 | * Description: 287 | * Read a value from the specified plist 288 | * 289 | * @param $a - the value to read 290 | * @param $b - plist to read the values from 291 | * @return bool false if not found, string if found 292 | */ 293 | public function get( $a, $b ) { 294 | 295 | if ( file_exists( $b ) ): 296 | if ( file_exists( $this->path.'/'.$b ) ): 297 | $b = $this->path.'/'.$b; 298 | endif; 299 | elseif ( file_exists( $this->data."/".$b ) ): 300 | $b = $this->data."/".$b; 301 | elseif ( file_exists( $this->cache."/".$b ) ): 302 | $b = $this->cache."/".$b; 303 | else: 304 | return false; 305 | endif; 306 | 307 | exec( 'defaults read "'. $b .'" '.$a, $out ); // Execute system call to read plist value 308 | 309 | if ( $out == "" ): 310 | return false; 311 | endif; 312 | 313 | $out = $out[0]; 314 | return $out; // Return item value 315 | } 316 | 317 | /** 318 | * Description: 319 | * Read data from a remote file/url, essentially a shortcut for curl 320 | * 321 | * @param $url - URL to request 322 | * @param $options - Array of curl options 323 | * @return result from curl_exec 324 | */ 325 | public function request( $url=null, $options=null ) 326 | { 327 | if ( is_null( $url ) ): 328 | return false; 329 | endif; 330 | 331 | $defaults = array( // Create a list of default curl options 332 | CURLOPT_RETURNTRANSFER => true, // Returns the result as a string 333 | CURLOPT_URL => $url, // Sets the url to request 334 | CURLOPT_FRESH_CONNECT => true 335 | ); 336 | 337 | if ( $options ): 338 | foreach( $options as $k => $v ): 339 | $defaults[$k] = $v; 340 | endforeach; 341 | endif; 342 | 343 | array_filter( $defaults, // Filter out empty options from the array 344 | array( $this, 'empty_filter' ) ); 345 | 346 | $ch = curl_init(); // Init new curl object 347 | curl_setopt_array( $ch, $defaults ); // Set curl options 348 | $out = curl_exec( $ch ); // Request remote data 349 | $err = curl_error( $ch ); 350 | curl_close( $ch ); // End curl request 351 | 352 | if ( $err ): 353 | return $err; 354 | else: 355 | return $out; 356 | endif; 357 | } 358 | 359 | /** 360 | * Description: 361 | * Allows searching the local hard drive using mdfind 362 | * 363 | * @param $query - search string 364 | * @return array - array of search results 365 | */ 366 | public function mdfind( $query ) 367 | { 368 | exec('mdfind "'.$query.'"', $results); 369 | return $results; 370 | } 371 | 372 | /** 373 | * Description: 374 | * Accepts data and a string file name to store data to local file as cache 375 | * 376 | * @param array - data to save to file 377 | * @param file - filename to write the cache data to 378 | * @return none 379 | */ 380 | public function write( $a, $b ) 381 | { 382 | if ( file_exists( $b ) ): 383 | if ( file_exists( $this->path.'/'.$b ) ): 384 | $b = $this->path.'/'.$b; 385 | endif; 386 | elseif ( file_exists( $this->data."/".$b ) ): 387 | $b = $this->data."/".$b; 388 | elseif ( file_exists( $this->cache."/".$b ) ): 389 | $b = $this->cache."/".$b; 390 | else: 391 | $b = $this->data."/".$b; 392 | endif; 393 | 394 | if ( is_array( $a ) ): 395 | $a = json_encode( $a ); 396 | file_put_contents( $b, $a ); 397 | return true; 398 | elseif ( is_string( $a ) ): 399 | file_put_contents( $b, $a ); 400 | return true; 401 | else: 402 | return false; 403 | endif; 404 | } 405 | 406 | /** 407 | * Description: 408 | * Returns data from a local cache file 409 | * 410 | * @param file - filename to read the cache data from 411 | * @return false if the file cannot be found, the file data if found. If the file 412 | * format is json encoded, then a json object is returned. 413 | */ 414 | public function read( $a ) 415 | { 416 | if ( file_exists( $a ) ): 417 | if ( file_exists( $this->path.'/'.$a ) ): 418 | $a = $this->path.'/'.$a; 419 | endif; 420 | elseif ( file_exists( $this->data."/".$a ) ): 421 | $a = $this->data."/".$a; 422 | elseif ( file_exists( $this->cache."/".$a ) ): 423 | $a = $this->cache."/".$a; 424 | else: 425 | return false; 426 | endif; 427 | 428 | $out = file_get_contents( $a ); 429 | if ( !is_null( json_decode( $out ) ) ): 430 | $out = json_decode( $out ); 431 | endif; 432 | 433 | return $out; 434 | } 435 | 436 | public function filetime( $a ) 437 | { 438 | if ( file_exists( $a ) ): 439 | if ( file_exists( $this->path.'/'.$a ) ): 440 | return filemtime($this->path.'/'.$a); 441 | endif; 442 | elseif ( file_exists( $this->data."/".$a ) ): 443 | return filemtime($this->data.'/'.$a); 444 | elseif ( file_exists( $this->cache."/".$a ) ): 445 | return filemtime($this->cache.'/'.$a); 446 | endif; 447 | 448 | return false; 449 | } 450 | 451 | /** 452 | * Description: 453 | * Helper function that just makes it easier to pass values into a function 454 | * and create an array result to be passed back to Alfred 455 | * 456 | * @param $uid - the uid of the result, should be unique 457 | * @param $arg - the argument that will be passed on 458 | * @param $title - The title of the result item 459 | * @param $sub - The subtitle text for the result item 460 | * @param $icon - the icon to use for the result item 461 | * @param $valid - sets whether the result item can be actioned 462 | * @param $auto - the autocomplete value for the result item 463 | * @return array - array item to be passed back to Alfred 464 | */ 465 | public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $auto=null, $type=null ) 466 | { 467 | $temp = array( 468 | 'uid' => $uid, 469 | 'arg' => $arg, 470 | 'title' => $title, 471 | 'subtitle' => $sub, 472 | 'icon' => $icon, 473 | 'valid' => $valid, 474 | 'autocomplete' => $auto, 475 | 'type' => $type 476 | ); 477 | 478 | if ( is_null( $type ) ): 479 | unset( $temp['type'] ); 480 | endif; 481 | 482 | array_push( $this->results, $temp ); 483 | 484 | return $temp; 485 | } 486 | 487 | } --------------------------------------------------------------------------------