Last active
May 19, 2024 13:49
-
-
Save cliffordp/8bfc4fee7161ceff3ac9191062a866af to your computer and use it in GitHub Desktop.
Thanks for the help at https://www.alfredforum.com/topic/10059-comma-separated-build-and-open-multiple-urls/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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/8bfc4fee7161ceff3ac9191062a866af 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://help.gohighlevel.com/support/tickets/12345 | |
* https://help.gohighlevel.com/support/tickets/281928 | |
* | |
* Also works with single selections: | |
* "902170" | |
* "9021.70" | |
* "-9 02-1x.70" | |
* will all result in: | |
* https://help.gohighlevel.com/support/tickets/902170 | |
*/ | |
// CHANGE THIS if you want it to work for a different site, such as https://app.codeable.io/tasks/ | |
$url_base = 'https://help.gohighlevel.com/support/tickets/'; | |
// 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