I got up a bit too early this morning. I finished a sprint on a freelance project but wasn’t ready to dig into my other big stuff yet. That stuff’s for after 5am. Before 5am is Bunch time. As promised, I haven’t written a blog post for every update, but you can find the full list of recent changes in the changelog.
If you don’t know what Bunch is, it’s an app I wrote for batch launching apps, opening files, toggling Do Not Disturb and a dozen other things. Start with the docs.
There are a few apps that I launch in Bunches that don’t respond to the XX
command that would normally close all open windows for the app. Bunch uses an AppleScript “close every window” command to do this, and some apps by their nature just don’t like that. In Tower, for example, that command won’t work, but typing ⌥⌘W
will. So, clearly, that’s what Bunch needed to be able to do.
In the file parameters for an app, you can now specify shortcuts to send to the app, or full strings to type out. The latter being less useful, but I already had the code for it. So it happened.
To specify a shortcut, you just surround it in curly brackets. So for the previous example:
Tower
- {~@w}
- ~/Code/Bunch
That will send the Close All Windows shortcut and then open the Bunch repository. You’ll note that the shortcut is specified with some odd characters. These map to the same characters used by key bindings in macOS:
symbol | key |
---|---|
$ |
Shift |
~ |
Option |
@ |
Command |
^ |
Control |
You can send multiple shortcuts in sequence just by adding a space between them within the curly brackets:
Sublime Text
- {@a @c @v @v}
Which would, for whatever reason, perform a select-all, copy, paste, paste in the frontmost window of Sublime Text. Obviously not a good example: in addition to being pointless it presupposes that a window is already open, which isn’t a safe assumption in a Bunch. But anyway, you can send sequences.
You can also type text. Like I said, this is less useful than sending shortcuts, but if you need to send a series of regular keystrokes to an app, you can do so using square brackets. Within these strings there are a few “escape” codes you can use, specified using a double backslash.
escape | key | mnemonic |
---|---|---|
\\n |
Return | newline |
\\t |
Tab | tab |
\\b |
Left Arrow | back |
\\f |
Right Arrow | forward |
\\p |
Up Arrow | previous |
\\n |
Down Arrow | next |
In your Bunch file:
- TextEdit
- {@n}
- [- First item\\n\\t- Second item\\n]
This would create a new file and insert (note the newlines and tab):
- First item
- Second item
If you actually find a clever use for that second one, do tell.
The latest version is available for automatic update (Bunch->Check For Updates) or download from the project page. As always, it’s donationware and I sincerely thank everyone who’s found it useful enough to pitch in.