Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: A programmable tooltip on Mac OS (nanakorn.com)
242 points by tanin on April 20, 2020 | hide | past | favorite | 45 comments



> 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


Also worth noting that you can pipe the result to `pbcopy` to put it in your clipboard. Super useful if you haven't seen it before.

    $ date -r 1577733633 | pbcopy


I think the example was silly, but think about finding the epoch in, say, a log file. With this system you could just click and see the human readable. With the date command you'd have to switch to terminal, type "date -r", paste, enter.


    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?


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


macOS has BSD date and Linux ships with GNU.


Yes! I was doing that for a while with a command-line tool. I couldn't make up my mind which way was faster. They were both required some sort of motor skill (e.g. switch to terminal, paste, enter) to perform the flows quickly.


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/

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


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


> 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!


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!


PopClip is fantastic... all kinds of useful extensions for it you can download.


One of them! Internally, the structure is called "pasteboard", and the clipboard is the "general" one. The OS uses this same data structure for transferring drag-and-drop data, which is the other common GUI mechanism for ad-hoc interoperability.


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).


However, I just checked—Alfred does pollute the clipboard with the selection when invoked like that. I guess OSX doesn't have an API to fetch the selection, other than via the services or the clipboard (maybe it's for the better, in terms of security).

IIRC some version of Keepass cleared passwords from the clipboard in such a way that even clipboard-history apps obeyed—but can't remember if this was in OSX or Linux. I wonder if this method could be used to pop the previous content back on the clipboard and leave no trace of the selection in the history.


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


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


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.


You can automate this, even if you have MFAs enabled. I do that through 1Password CLI (for the MFA token) and a script to interact with the idp. We use temp credentials, so after X hours you to generate a new session.

I'm just typing the 1Password password on the terminal, I could automate that part too but then essentially I'm removing all auth from my workflow which is dangerous especially on laptops.


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.


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


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
    }


Yes! That is a great use case.

One of tooltip item actions is opening URL.

I'm not sure if iTerm2 supports executing stuff through URL. (For example, we can open intellij using idea://.)

If not possible, please open a GitHub issue or reply here. We can figure it out together. We might be able to get Tip to support triggering iTerm2 somehow natively.

Thank you sharing an interesting use case!


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


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.


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.


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

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


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.


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.


> 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!


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.


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.


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.


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.


> 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!


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!


Looks pretty neat.


Thank you! any feedback is welcome.


Oh wow. Plugin to translate chinese to english?


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/


Unfortunately, you would have to write your own provider script to do the translation.

Otherwise, PopClip would be a great out-of-the-box alternative.


ออซัม


Well, awesome :)


I saw it but title did not justice it.


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




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: