Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active August 12, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/a0ce681f51504649cd75cc9c22a53b2a to your computer and use it in GitHub Desktop.
Save cliffordp/a0ce681f51504649cd75cc9c22a53b2a to your computer and use it in GitHub Desktop.
<?php
//
// Do NOT USE OPENING <?php TAG IN ALFRED APP
//
/**
* Open 1 or more (comma or new line separated) issue number URLs from selection.
*
* @link https://github.com/cliffordp/alfred-app-workflows Download this Alfred App Workflow's code (and more).
* @link https://gist.github.com/cliffordp/a0ce681f51504649cd75cc9c22a53b2a This Alfred App Workflow's code snippet.
*
* Example selections (without quotes):
* "12345,281928" // comma without space
* "12345, 281928" // comma with space
* "12c345,281928" // non-numeric
* "12345
* 281928" // separated with line break, such as a Google Sheets column
* will all result in the same: opening the following URLs in the default browser:
* https://central.tri.be/issues/12345
* https://central.tri.be/issues/281928
*
* Also works with single selections:
* "902170"
* "9021.70"
* "-9 02-1x.70"
* will all result in:
* https://central.tri.be/issues/902170
*/
// CHANGE THIS if you want it to work for a different site, such as https://app.codeable.io/tasks/
$url_base = 'https://central.tri.be/issues/';
// turn New Lines into commas
$query = str_replace( PHP_EOL, ',', "{query}" );
// convert Query to array
if ( false === strpos( $query, ',' ) ) {
$array = array( $query );
} else {
$array = explode( ',', $query );
}
// open each URL
foreach ( $array as $key => $value ) {
$value = preg_replace( '/\D/', '', $value ); // remove any non-digit
$value = (int) $value;
$url = '';
if ( -1 < $value ) { // if $value is zero or greater
$url = sprintf( '%s%d', $url_base, $value );
if ( ! empty( $url ) ) {
system( "open $url" );
}
} else {
continue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment