Jump to content

How can I configure a workflow to show the current time if I type time into alfred?

Recommended Posts

Thanks Vitor.


I tried what I saw in the picture, but no luck.


I think my script block is ok.

I have "tell application Alfred 3 to search show_time and I see the words "show_time" pop up in Alfred when i hit the assigned keystroke, so that part is working.

The next line does a command-shift left arrow, selecting all the text. I don't need that so I removed it.


What I'm not understanding is, how do I get the actual time to display, in the screenshots on that post it looks like the person who asked the question got a region to display right under alfred - how is that done?


Also in the filter, I see where it /might/ be pulling the time command from the command line, but since I'm not seeing any output, I'm not sure if that's working.


Thanks Vitor!

Link to comment

Edit, never mind, I had Argument required in the filter, taking that off worked.


I renamed a few things to 'time' and now I see the time as one of the many search results that match 'time'


Ideally I'd like it on top, but Alfred seems to prioritize based on most used so the 2nd time I did it, the time was at the top.


I'll fool around in the workflow system to see if I can find an option to force a result to the top.


Thanks again Vitor!

Link to comment

You can get the current time with the shell command date "+%H:%M:%S" and you can tell Alfred to display some text in its results list by passing it JSON from a Script Filter.
So, create a Script Filter with the keyword "time" and No Argument. Then put this in the Script box (leave Language set to /bin/bash): 

t=$(date "+%H:%M:%S")
cat <<EOS
{ "items": [ {"title": "$t"} ] }

That will return one result to Alfred, containing the current time.
You're always likely to have an issue with other results using a common word like "time" as the keyword. I generally prefix my keywords with ".", which will exclude all of Alfred's default results. For this Script Filter, I might use ".t" instead of "time".

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...