Jake.codes

AlfredRun, a URL Scheme for Alfred

Saturday, February 15, 2014

This is a fork of a project by Chase Nordengren

Enables the use of a custom URL scheme to run commands in Alfred 2 (OS X).

Credits

Code based on a template by Drosophiliac.

Installation

Move compiled Applescript Bundle Alfred Run.app into your /Applications folder.

Usage

Run the URL scheme “alfredrun://foo” from any browser, where ‘foo’ refers to a command in Alfred. Use “%20” to preseve spaces in command.

Example: alfredrun://foo%20bar%20bat

Advanced Usage Ideas:

Alfred commands can be run remotely using an iOS application like Command-C, perhaps saving frequently used commands in Launch Center Pro. To preserve spaces in commands in Launch Center Pro, wrap the text of the alfred command in double curly brakets, and break spaces with “%20”.

Example:
command-c://x-callback-url/copyAndOpenURL?deviceName=foo&url=alfredrun://

Example with Prompt:
command-c://x-callback-url/copyAndOpenURL?deviceName=foo&url=alfredrun://

iOS Bookmarklet, handy for those who do not use Launch Center Pro

Simple, just add this as a bookmark’s location. - Don’t forget to add your device name! (url encoded)
javascript:var%20deviceName%3D%27YOURCOMPUTERNAME%27%2CyourCommand%3Dwindow.prompt%28%27AlfredRun%27%29%3Blocation.href%3D%27command-c%3A%2F%2Fx-callback-url%2FcopyAndOpenURL%3FdeviceName%3D%27%2BencodeURIComponent%28deviceName%29%2B%27%26url%3Dalfredrun%3A%2F%2F%27%2BencodeURIComponent%28encodeURIComponent%28yourCommand%29%29%3B

Build your own using PHP - Don’t forget to add your device name! (It will url encode for you)

<?
    echo 'javascript:' . rawurlencode("var deviceName='YOURCOMPUTERNAME',yourCommand=window.prompt('Alfred Run');location.href='command-c://x-callback-url/copyAndOpenURL?deviceName='+encodeURIComponent(deviceName)+'&url=alfredrun://'+encodeURIComponent(encodeURIComponent(yourCommand));");
?>