Skip to content

Tip 2.0 supports executing an arbitrary command

Tanin Na Nakorn edited this page Jun 8, 2020 · 1 revision

Since we released version 1.0, we've been getting a lot of feedback and ideas.

One HN comment that struck me is that there seem to be some complex use cases that others can utilize Tip. A few days later, another user opened the issue asking about executing an arbitrary command. This is such a great idea.

With Tip 2.0, we can do exactly that. We can write our provider script to return the execute item like below:

#!/usr/bin/env ruby

if ARGV[0] == "--execute" && ARGV[1] == "send_note"
  File.write('/Users/tanin/projects/notes/my_notes', "- #{ARGV[2]}\n", mode: 'a')
  puts []
else 
  puts [
    {"type": "execute", "label": "Send to my note file", "args": ["--execute", "send_note", "#{ARGV[0]}"]}
  ]
end

When the item, Send to my note file, is selected by the user (i.e. you), Tip invokes the provider script against with ./provider.script --execute send_note the-selected-text, which is the value of args.

Supporting execute is interesting and powerful. You can code the provider script to do anything you can imagine since the provider runs is user space using NSUserUnixTask.

You might notice puts [] above. This means that Tip will close after it executes the command. However, if we print tip items there, a new tooltip will show up. This means you can code a flow of tooltips by utilizing the execute tip item.

In the next version, I'm planning to allow user input on the tooltip. I already have one use case in mind, which is to calculate percentage on the selected number.

My hope is Tip will replace some of our workflows and reduce our hand movement, and eventually Tip will help save us from the injury of overusing our hands.

Happy Tipping!

Protip: You can map an extra mouse button and a trackpad gesture to emit your Tip's shortcut. This will greatly the reduce friction of using Tip. I use Noo.app (Disclaimer: I built it). Any other app would work equally well.