cliffordp
2/27/2017 - 5:16 PM

Thanks for the help at https://www.alfredforum.com/topic/10059-comma-separated-build-and-open-multiple-urls/

<?php
//
// Do NOT USE OPENING <?php TAG IN ALFRED APP
//

// Download this code as an Alfred App Workflow at https://cl.ly/0Y3k2l0d2k40

/**
 * Comma-separated, build and open multiple URLs
 * from https://gist.github.com/cliffordp/a0ce681f51504649cd75cc9c22a53b2a/
 *
 * Example selections (without quotes):
 *   "12345,281928"
 *   "12345, 281928"
 *   "12c345,281928"
 * will all result in the same: opening the following URLs in the default browser:
 *   https://example.com/issues/12345
 *   https://example.com/issues/281928
 *
 * Also works with single selections:
 *   "902170"
 *   "9021.70"
 *   "-9 02-1x.70"
 * will all result in:
 *   https://example.com/issues/902170
 */

$query = "{query}";

$url_base = 'https://example.com/issues/';

if ( false === strpos( $query, ',' ) ) {
	$array = array( $query );
} else {
	$array = explode( ',', $query );
}

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;
	}
}