Jump to content

Generating URL/filename slugs (clean URLs) with Alfred 2

Recommended Posts

Hi all,


I made a workflow to allow easily generating filename slugs with Alfred 2. All the details, screenshots and download are here: http://mattgemmell.com/2013/03/26/generating-filename-slugs-with-alfred-2/


'Slugs' are URL/filename-safe versions of strings, commonly used for filenames or in permalinks or CMS systems. So, for example, "Alfred 2 is fab!" would become "alfred-2-is-fab".


My workflow allows setting a default filename-extension (which you can always override on a case-by-case basis), and offers plain, date-prefixed, and date-and-time-prefixed versions of slugs. See the blog post for more.


Hope you find it useful.






Link to comment
  • 11 months later...

Very handy! Especially because I have an English system but want German slugs. Always appreciated when coders take such unusualness into account.

Found 1.5 bugs, though.

The locale is set to "de" by default in the script filter (which is great for me, but might not be what others want).

Also, get_osx_system_locale doesn't work as intended if there's no hyphen in the default system locale (it will return the script default "en" instead).

Anyone for whom this is a problem should change get_osx_system_locale in slug.php to:


function get_osx_system_locale($full = false) {
	// If $full is true, you MIGHT get locales like "en-US", or just "en".
	// If $full is false, you'll ALWAYS get locales like just "en".

	$lang = "en";
	$raw_locs = array();
	exec('defaults read .GlobalPreferences AppleLanguages | tr -d [:space:]', $raw_locs);

	$locs_str = trim($raw_locs[0], "()");
	$locs = explode(",", $locs_str);
	$lang = trim($locs[0], "\"");

	if (!$full) {
		// Strip language variant.
		$dlelim_posn = strpos($lang, "-");
		if ($dlelim_posn !== false) {
			$lang = substr($lang, 0, $dlelim_posn);

	return $lang;
Edited by deanishe
Link to comment
  • 1 month later...

Hi Matt,

As I said I love this workflow and have used it for a little while.
What I was wondered is how I could convert or duplicate and make this to go the other way. So to convert a slug string back into a normal string so for example. terry-has-a-slug-with-a-title to be converted into Terry Has a Slug with a Title (or even just all lowercase).

So an un-slug if you will.


Link to comment

That is trivially simple to do, but you'd have to accept that some information has probably gone missing when generating the slug.

In Python, you'd just do:

title = slug.replace('-', ' ').title()

Trying to put back non-ASCII characters, however, is a can of worms.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...