Apple - Need menu bar app to show output of Terminal command every 60s
#!/usr/bin/env ruby
require "osx/cocoa"
include OSX
app = NSApplication.sharedApplication
statusitem = NSStatusBar.systemStatusBar().statusItemWithLength(NSVariableStatusItemLength)
while true
statusitem.setTitle(rand(999))
sleep 1
end
app.run
(If anyone who actually knows Cocoa wants to improve this, feel free to edit.) I more or less just copied the script from taw's blog: Personal experience points and OSX menulets, which was mentioned in display - Is there a way to have AppleScript output displayed in the menubar? - Apple.
Here is the solution in python.
Install rumps framework (linked repository has patch for OS X 10.9.3)
sudo pip install git+https://github.com/tito/rumps
You might need to adjust $PYTHONPATH
to include pyobjc (Foundation)
export PYTHONPATH=/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Adjust the following code for your needs:
#!/usr/bin/env python
import rumps
import os
import threading
class AwesomeStatusBarApp(rumps.App):
def __init__(self):
super(AwesomeStatusBarApp, self).__init__("Awesome App", "Title")
tail(self)
def tail(self):
threading.Timer(5, tail, [self, ]).start()
self.title = os.popen("tail -1 /var/log/system.log").read()[0:-1][0:50]
AwesomeStatusBarApp().run()
Do not forget to limit the length of the string ([0:50]
) (or OS X will remove it in favor of menus if they both don't fit), and get rid of the newline in the end ([0:-1]
)
There is another recent open source alternative called BitBar (MIT License), which appears very similar to "TextBar" and "ShellWrangler" and amazes through its simplicity.
You can execute scripts at any time interval that is encoded in the script file name (e.g. my_script.60s.py) and it can execute any script you can also execute in your Terminal.