Execute Ruby Script
by Ian Kirkland
This action executes Ruby code without having to mess with hashbangs, escaping, etc.. While there's certainly nothing preventing you from running ruby code via Keyboard Maestro's built-in "Execute Shell Script" action, I personally favor the conceptual unambiguity of a separate Ruby action.
As with other Keyboard Maestro actions, results saved to Keyboard Maestro variables come in as text strings. So, if your Ruby code returns fixnums, hashes, arrays, booleans, etc., please remember that you're always going to end up with the literal (text) representation of whatever it is. Just dig into the action's source code if you're curious about what's under the hood.
Important Things to Remember
This action behaves like normal Ruby code; meaning escape only what you'd normally escape and leave be whatever you'd normally leave be. And – please – in true n00b humility, let me know if this plugin can be improved. (This is how we learn, and I am all ears.)
- If you come up with any creative uses for the action – or come across any deal-killing bugs – please share them here in the comments
- I have a highly-involved 9-to-5 job that I'm very passionate about. Visit here if you want to know more: Better Homes and Gardens Real Estate Bradfield Properties. That said, I can't guarantee 'lickety-split' fixes. However, please feel free to report bugs and other frustrations at: email@example.com
Download Action: km-execute_ruby_script.zip (412.1 KB)
To install, drop the .zip file onto Keyboard Maestro and it will install it as a Third Party Plug In action. If, for some reason the install fails, simply unzip and place the resulting folder in the Keyboard Maestro Actions directory in Application Support. You can locate this directory by copying the below path, and – in Finder's menubar – selecting "Go › Go to Folder...". Then paste the path into the text field that pops up:
~/Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions/
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.