
Show HN: A programmable tooltip on Mac OS - tanin
https://tanin.nanakorn.com/main/2020/04/19/use-tooltip-to-speed-up-your-workflow.html
======
jan_g
> Copying a millisecond-from-epoch number, visiting a website that can convert
> it to human-readable date, pasting the number, and hitting enter

I use the builtin `date` utility for this specific task, instead of querying
another webpage to translate it.

    
    
        $ date -r 1577733633
        Mon Dec 30 20:20:33 CET 2019

~~~
wjdp

        date -r 1577733633
        date: 1577733633: No such file or directory
    

...

    
    
       -r, --reference=FILE
              display the last modification time of FILE
    

...

Is OSX's date command different from Linux?

~~~
wjdp
Found it, for GNU it's `date -d @1577733633`

------
pcr910303
Looks somewhat similar to Popclip[0], but is less intrusive(user needs to be
explicit) and more visual(result is shown below).

Very interesting solution for text manipulation. (A bit off topic but...)
Seeing these tools which primary interaction happens with the clipboard make
me think that the GUI equivalent of UNIX pipes is the clipboard — it allows
programs to interoperate in an unstructured fashion.

[0]: [https://pilotmoon.com/popclip/](https://pilotmoon.com/popclip/)

[edit]: fixed typo & changed some words to convey my meaning better.

~~~
tanin
Yes, it's quite similar to PopClip!

Tip is less intrusive and targets programmers (because your provide the
script). PopClip is more out-of-the-box and more automatic (I assume PopClip
monitors mouse events, but not sure).

I wanted to build Tip for Ubuntu as well but I couldnt find a good mechanism.
Mac OS's system-wide service is such a beautiful mechanism. Slick and offer
the right level of privacy.

Quick note on text manipulation. Mac's system-wide service can modify text as
well!... But sadly I couldn't make it work in a slick way. I might need to
attempt at it again

~~~
OJFord
> I wanted to build Tip for Ubuntu as well but I couldnt find a good
> mechanism.

The selected text would already be on the 'PRIMARY' uh.. clipboard (I hesitate
because that's not the 'CLIPBOARD' one and I'm not sure of the genetic term).
I would then use dmenu (or equivalent, e.g. rofi) to show the options
generated by the script running on the selection.

That wouldn't be a tooltip, (unless there are dmenu-like programs that can be
configured to appear at the pointer, I'm not sure) but is probably how most
Linux users would expect/want it to appear.

To be honest though, since the target user is already supplying the script to
generate it, I think you've given the value you can in the idea, and they're
best placed to know how to integrate it into their existing tools most
effectively.

For example, using i3 & dmenu:

    
    
        bindsym <shortcut keys> exec xsel | thescript.sh | dmenu
    

If the user's writing the script anyway, they can write that, and the details
vary according to the window manager (or other tool used to bind keys) and the
dmenu-like used to display them. Some may also prefer a different/better
integration with their clipboard manager.

My basic point is that Linux systems are too 'fragmented' and this is too easy
for you to a better job once for everybody than they can each do once for
themselves.

It's a great idea though, I'm certainly going to bear it in mind and see what
I do that could benefit from it, thanks!

~~~
tanin
Ah, yes, now I remember the clipboard on Ubuntu. A selected text is
immediately copied to clipboard, and we can use the middle mouse button to
paste

The idea is very interesting. Basically, I only build the part where Tip takes
the text and invokes a script. User then renders the tooltip themselves.

Thank you!

------
aasasd
You can do similar stuff with Alfred, which happens to already be quite useful
for frequent tasks. At least with Alfred 2, dunno about new versions. Create a
workflow, put in a single hotkey trigger block and choose for it to pop up
Alfred's window with the selection and the cursor in the beginning. I'm using
alt-shift-space as the key. Now you can select text, mash the hotkey and run
any of the other workflows that have a ‘keyword’ assigned, plus have ‘script
filters’ populate the result/tip list before anything is run. I'm using this
to invoke search engines or to add notes in Org-mode, without bothering with
the clipboard.

While I'm on this topic, let me add that Lua is way faster than Python or even
JS, so it enhances the responsiveness if used for workflow scripts or ‘script
filters’.

I'm also using the Automate app on Android to very similar ends: it can have
your workflows invoked via the text selection menu or through sharing (no
addons with more payment and embedded ads code necessary, like with Tasker).

~~~
AriaMinaei
Thank you for this. Been using Alfred for years and didn't know text selection
could be fed to workflows.

~~~
aasasd
Same here, actually: used Alfred for a long time, finally got fed up with
juggling the clipboard just a couple months ago.

------
Corrado
This looks like it might help me do something I do multiple times a day. I
work with multiple AWS accounts and have to sign in to several different ones
each day.

Currently, I have to: \- sign in to AWS SSO \- choose an account \- copy the
ENV VARs to my clipboard \- select an iTerm2 tab \- paste ENV VARs into the
tab

Using 'tip' I think I could automated the last 3 steps. It's a small win, but
when you do it multiple times a day it adds up.

~~~
nathancahill
Can you use the profiles in ~/.aws/credentials? This is my lifeblood as a
freelancer working with many clients and switching AWS accounts all day.

~~~
weiming
Yep. AWS commands take the --profile argument to choose one of the items from
the credentials file.

~~~
nicoburns
You can also use the following bash/zsh function to quickly set the current
default profile (requires ruby):

    
    
        function aws_switch () {
            local env="$1"
            local region="$2"
            export AWS_DEFAULT_PROFILE="$env"
            export AWS_ENV="$env"
            export KITCHEN_ENV="$env"
            export AWS_ACCESS_KEY_ID=$(/usr/bin/env ruby -e "require 'inifile'; puts IniFile.load(File.join(File.expand_path('~'), '.aws', 'credentials'))[ENV['AWS_DEFAULT_PROFILE']]['aws_access_key_id']")
            export AWS_SECRET_ACCESS_KEY=$(/usr/bin/env ruby -e "require 'inifile'; puts IniFile.load(File.join(File.expand_path('~'), '.aws', 'credentials'))[ENV['AWS_DEFAULT_PROFILE']]['aws_secret_access_key']")
            if [ -z "$region" ]
            then
                export AWS_REGION=$(/usr/bin/env ruby -e "require 'inifile'; puts IniFile.load(File.join(File.expand_path('~'), '.aws', 'config'))['profile ' + ENV['AWS_DEFAULT_PROFILE']]['region']")
            else
                export AWS_REGION="$region"
            fi
            export AWS_DEFAULT_REGION=$AWS_REGION
        }

------
dmitriid
Awesome. Exactly what the all-but-abandoned "services" concept was supposed to
do in MacOS (replaced by the all-but-abandoned extensions).

~~~
robenkleene
To me this is one of the great mysteries of computers: Why don't people use
these features more? I have tons of Services that I use all day, for me
they're one of the most important features of the OS (archiving text, opening
all selected URLs, and converting the selection to title case are some
examples). Yet Services don't seem popular, why is that? People seem to
customize their shells (e.g., write Bash scripts, make aliases, and customize
their prompts), and even non-programmers seem to be able to accomplish complex
automation in Excel, or with a tool like Zapier. So why don't people customize
their OS similarly? I find the gains to be greater, because if I customize at
the OS-level, my customizations are useful in any app, and forever, instead of
being tied to a particular app or project.

~~~
tanin
Services is hard to google. The term is overloaded.

I think it's called (or was called at some point) "system-wide services". But
official doc doesn't use this term.

I was simply fortunate to stumble upon it. Initially, I was thinking about
building Tip on clipboard (or pasteboard), which would have been inferior.

------
jtbayly
The title doesn’t do it justice once I saw it.

These aren’t simply tool tips. They are actions.

~~~
tanin
You're right. I'm finding a way to explain it better.

Tip shows related actions that can be performed on a piece of text.

A suggestion is very welcome here.

------
aasasd
Btw, if you want to be even lazier and not involve the other hand—services can
be run from the context menu (which is a bit busy but at least it's
available).

Also, regarding Swift, the language is pretty simple: I did't know either ObjC
or Swift but was able to make a small program in it. The most annoying thing
is that Swift's APIs and types constantly change between versions, so you have
to translate between the docs and your version of OSX.

~~~
tanin
> Btw, if you want to be even lazier and not involve the other hand—services
> can be run from the context menu (which is a bit busy but at least it's
> available).

Yes, Right clicking and selecting the menu manually works as well. Thank you
for mentioning it.

My setting is that my mouse has an extra button, so I configure the extra
mouse button to emit Cmd+F3 (which triggers Tip). It's a one-hand one-click
operation!

------
sneak
This is neat, reminds me a little of Apple Data Detectors, a text selection
parsing thing that Apple shipped around System 8 or so. I still miss it.

------
sportsaw
I haven’t used the Acme text editor, but this reminds me of what I have read
about it in that any text can be a command. Very neat looking.

~~~
tanin
That's a good way of thinking about it.

The fundamental of Tip is that every piece of text has a relevant set of
actions.

------
nonninz
This is fantastic, thank you.

I have two questions:

1\. Did you decide against including any script in the app bundle for more
privacy? It looks like it.

2\. So all scripts must be appended in that same file? Have you thought about
a behavior like a ".d" directory in the recent "Unix world", where each file
can add configuration options? That would enable using different scripts and
different languages.

~~~
tanin
> 1\. Did you decide against including any script in the app bundle for more
> privacy? It looks like it.

Sorta.

My initial use case didn't need a bundled script. My current script involves
heavily my local env (e.g. credentials, searching local file). Some use cases
are very specific to company's internals (e.g. lookup user id).

I might consider embed a script. But I haven't given it much thought yet, and,
because of App Sandbox, the script wouldn't be able to do much.

> 2\. So all scripts must be appended in that same file? Have you thought
> about a behavior like a ".d" directory in the recent "Unix world", where
> each file can add configuration options? That would enable using different
> scripts and different languages.

Yes, that's some what in a roadmap. For now, you can workaround by having the
main script calls out to the other script

Thank you for the questions. Please don't hesitate to let me know how it works
for you!

------
hobofan
Awesome!

For a lot of my personal productivity tools, I've been using Alfred, but for
some of them a tooltip would be a lot more natural. Looking forward to using
it!

------
ymt_1503
Looks pretty neat.

~~~
tanin
Thank you! any feedback is welcome.

------
baby
Oh wow. Plugin to translate chinese to english?

~~~
chris_st
I use PopClip[0] (recommended above). One of the extensions you can download
sends whatever you've selected to Google Translate. Don't need it often, but
it's fantastic when I do.

0: [https://pilotmoon.com/popclip/](https://pilotmoon.com/popclip/)

------
HABytes
I saw it but title did not justice it.

~~~
tanin
I'm open to a suggestion on how to explain it in a better way.

------
macarthy12
ออซัม

~~~
tanin
Well, awesome :)

