Jump to content

Show uptime notification


Recommended Posts

I created a small workflow displaying the system's uptime in a notification.

 

Download

 

This is also useful as an example for integrating scripts in your workflow.

 

Enjoy.

 

- David

 

EDIT: corrected the download link to a private hosting provider, wikisend appears to be dubious. Sorry for any inconvenience.

Edited by dave
Link to comment
  • 2 weeks later...

I was wondering about the 12MB file too. "small workflow"?? And didn't install it.

by the way I was wondering.. not talking about anyone here but can fraudulent people do strange things with alfred workflows when they distribute them here?

Link to comment

@DJay — There is the possibility. Since the workflows allow for pretty much any script to be run, then malicious code is easy to install (even if it is just to use curl to download something else). Currently, there isn't any mechanism to automatically flag a workflow as having malicious code. Any user can reply to a forum post declaring malicious code and report the post that has it, but those are the only mechanisms that exist currently.

 

With the Extras page for the Alfred2 website, there will be some featured workflows that will be safe and vetted (I'm sure). With Olivier's repo, currently each workflow and theme needs to be approved, but I'm not sure how much checking will be involved in there because I'm sure that there will be many submissions, and it would take quite a lot of volunteer time to sort through them all.

 

Anything posted here can be vetted only by the community. I have faith that 99% of the users here will post great workflows, and users who have posted many workflows before can easily be trusted, but there is always the possibility that someone can upload a malicious workflow.

 

Be diligent?

Link to comment

@rice.shawn — Thanks a lot for these information and your thoughts. I really appreciate the community here. swapping ideas and great workflows.

And of course I think as you mentioned the most girls and boys here are honest. :)

Edited by DJay
Link to comment

And if you just want to know the days, hours and minutes since last reboot, you can use the following term:

uptime | sed -e 's/,.[0-9]*.user.*//' -e 's/^.*up *//'

 

this would f.e. result in

2 days,  7:28
Link to comment

Just in case anyone would be interested: Another method of formatting the uptime output:

 

 

 

uptime | awk '{sub(/[0-9]|user,|users,|load/, "", $6); sub(/mins,|min,/, " minutes", $6); sub(",", " minutes", $5); sub(":", " hours ", $5); sub(/hrs,|hr,/, " hours", $4); sub("h ", " hours ", $4); sub(/days,/, " days ", $4); sub(":", " hours ", $3); sub(",", " minutes", $3); print "" $3 $4 $5 $6}' | sed -e 's/ 1 days/ 1 day/g' -e 's/ 1 hours/ 1 hour/g' -e 's/1 minutes/1 minute/g' -e 's/usermin//g'
 

 

 

This will output, in my case: "19 days 17 hours 45 minutes"

It's just a tad more human readable, although I find the length of the awk to be a bit ironic

Link to comment

I would prefer to have the script distinguish between day/days, hour/hours and minute/minutes if moving from the current really plain approach to a more sophisticated implementation. No need for a cryptic perl/sed/awk script, though. Simple, understandable php, python or shell is fine. Anyone?

Link to comment

Nice RodgerWW.. Thanks.

 

But looks a bit strange here.

Would great to have "0 days, 8 hours, 28  minutes".

Whats the 1user minutes?

 

Bildschirmfoto%202013-04-08%20um%2018.02

 

 

OK, in lieu of using "uptime" I personally found "system_profiler SPSoftwareDataType | grep 'Time since boot'" to be a bit easier to parse with only one return, as I am very new to awk and grep.

 

 

So, the initial command "system_profiler SPSoftwareDataType | grep 'Time since boot'" will return:

 

Time since boot: 20 days 11:19

 

NEW code:

 

 

system_profiler SPSoftwareDataType| grep 'Time since boot' | awk '{sub(/Time since boot:/, ""); sub(":", " hours ", $3); sub("", "minutes", $4);print "" $0}'| sed -e 's/ 1 days/ 1 day/g' -e 's/ 1 hours/ 1 hour/g' -e 's/00 minutes/0 minutes/g' -e 's/01 minutes/1 minute/g' -e 's/02 minutes/2 minutes/g' -e 's/03 minutes/3 minutes/g' -e 's/04 minutes/4 minutes/g' -e 's/05 minutes/5 minutes/g' -e 's/06 minutes/6 minutes/g' -e 's/07 minutes/7 minutes/g' -e 's/08 minutes/8 minutes/g' -e 's/09 minutes/9 minutes/g'

Will return:

 

20 days 11 hours 19 minutes

 

I'm using awk to to remove "Time since boot:", the time separator, and also to add the hours and minutes.

I'm using sed to modify the plural form of days/hours/minutes, and also to remove leading zeros.

 

I'm not sure how the singular days are displayed with 'Time since boot" (as I'm currently on 20 days and have no real reason to reboot my system currently), so I left out that sed formatting, but it can be added easily.

 

 

Edited by RodgerWW
Link to comment

I would prefer to have the script distinguish between day/days, hour/hours and minute/minutes if moving from the current really plain approach to a more sophisticated implementation. No need for a cryptic perl/sed/awk script, though. Simple, understandable php, python or shell is fine. Anyone?

 

I would agree 100% on this ... I WISH I knew how to do this myself ... Would be awesome to start at the epoch time, remove current time, and scriptually only show singular for year/month/day/week/hour/min ... seconds might be going a little too far though, lol. Oh, and also remove leading zeros.

 

So the perfect output: " 1 year 35 days 12 hours 1 minute "

Edited by RodgerWW
Link to comment
  • 8 years later...

8 yrs later - I run the Script in the current version of Alfred on MacOS 11.5.1 and I don't see a system notification.

 

When I use the debug logs I see: 

[11:46:42.690] Logging Started...

[11:47:10.253] Uptime[Keyword] Processing complete

[11:47:10.257] Uptime[Keyword] Passing output '' to Run Script

[11:47:10.264] Uptime[Run Script] Processing complete

[11:47:10.264] Uptime[Run Script] Passing output '6 days, 23:20

' to Post Notification

 

--

Something is happening with the notification. Perhaps I need to set a permission for Alfred to display notifications? ...

Link to comment
3 minutes ago, mlevison said:

Something is happening with the notification. Perhaps I need to set a permission for Alfred to display notifications?

 

Must say thanks for necroing this thread as I from time to time want to check this, but have been too lazy.

I downloaded the workflow and tested it directly without any issues.

Could it be that you deactivated notifications, maybe through "do not disturb"?

 

Otherwise I think you need to give Alfred permission via "Accessibility", to be able to post notification.

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