À la bonne Sainte-Force

Tools

Tags

Workcuts

20 November 2011

Dear friend,

Workcuts is a simple per-project keyboard shortcut and menu manager with Ruby scripting for fast access to your projects' most repeated tasks. I wrote it mainly because I needed it but couldn't find something likewise and extra-handsome at the same time.

Workcuts Þe Brave
Workcuts Þe Brave

Excerpt from the help document

The Sainte-Force preaches laziness, so I won't repeat myself and paste the help document in this section.

Download

How to use Workcuts

Workcuts is a simple Mac OS X application that opens projects and gives access to the project's shortcuts. A project is simply a folder in your computer. A shortcut is a command which can be associated with a keystroke.

Getting started

  • Download Workcuts (see above) and install it.
  • Open Workcuts.
  • Open a project with the Project > Open… menu. Remember, a project is just any folder.
  • If you press the global shortcut key (⌘⌥⌃Space by default), a menu appears in the bottom left corner of your screen. This is the shortcuts menu. Apart from the global shortcut key, you can find it in the Shortcuts menu (in the menu bar), in the Workcuts status item (if activated), or in the Workcuts dock menu.
  • You can see there's only one element in the shortcuts menu. It is called Edit Workcuts.rb…. Once activated, it opens the file called Workcuts.rb in your project directory, with your favorite editor. If no file has this name, Workcuts creates it automatically and fills it with example shortcuts. Yes, because it's the file that specifies what are the shortcuts for the current project. See below for a syntax description.
  • Save your Workcuts.rb file and Workcuts will update itself automatically. If there's an error in the file, Workcuts will nag you about it.
  • In order to use your shortcuts, show the shortcuts menu (for instance with the global keyboard shortcut) and then select the shortcut you want (for instance by pressing the shortcut's associated keystroke).

The project you're working on is kept across different executions of Workcuts.

Workcuts file syntax

The file must be called Workcuts.rb and be placed in the root of your project folder. Here is a minimal example for one shortcut :

shortcut :firstshortcut do
	named "My first shortcut"
end
The simplest shortcut ever.

A shortcut is defined by the word shortcut, followed by an identifier (an identifier is the colon character followed by letters, no spaces), followed by the word do, followed by one or more lines specifying the shortcuts properties, followed by the word end. You can have as many shortcuts as you want and you can specify a shortcut in several places, like this :

shortcut :firstshortcut do
	named "My first shortcut"
end

# …

shortcut :firstshortcut do
	press "A"
	will do
		# Ruby code
	end
end
Multiple definitions merge.

Please be aware that the entire Workcuts.rb file is itself a Ruby script (hence the extension). Specifying a shortcut's properties can be done by using the methods named (to tell its title), press (to tell its associated keystroke), will (to tell what command the shortcut will do in a Ruby block), toggle (to set/unset the shortcut tickmark), check/uncheck, alternative/noalternative

You can run any Ruby command you want, from simple calculations to shell commands. You can even create shortcuts dynamically.

Finally, Workcuts provides a special method, terminal, that enables you to launch commands in a new Terminal window, with the settings set specified in Workcuts' preferences :

terminal(script, exitafter = false, pressreturn = false)
The terminal method.

Now let's watch several examples !

Examples

Let's start with a simple (and useful) example. Note that calls to the shell are blocking !

shortcut :reveal do
	named "Reveal in Finder"
	press "o"
	will do
		`open .`
	end
end

shortcut :build do
	named "Make"
	press "b"
	will do
		puts `make 2>&1`
	end
end

shortcut :buildclean do
	named "Clean"
	press "Opt b"
	alternative
	will do
		puts `make clean 2>&1`
	end
end

shortcut :run do
	named "Run"
	press "r"
	will do
		terminal "./a.out", true, true
	end
end
Base for a programming project

Here is a slightly more complicated example.

Dir.new(".").each do |f|
	shortcut f.to_sym do
		named f
		will do
			`open #{f}`
		end
	end
end
Crazy : list each file in the current directory

Final thoughts

I hope this tool will prove to be useful to you. Feel free to send comments, bug reports, death threats…

Looking forward to hearing from you,
Hubert Sainte-Force