Logintime in menubar 1.1 source code

Project "Logintime in menubar.rbp"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem AppleAboutthisapplication = "About this application..."
End MenuBar
Class App Inherits Application
Sub Close() if s<>nil then s.Close DelayMBS 0.2 // wait for events to flush end if End
Sub Open() RegisterPlugins // Create statusitem s=new MyNSStatusItemMBS if s.CreateMenu then SetTitle else quit end if Exception System.DebugLog "Exception in "+CurrentMethodName quit End
Function UnhandledException(error As RuntimeException) as Boolean System.DebugLog "Exception in "+CurrentMethodName System.DebugLog "Name: "+Introspection.GetType(error).name System.DebugLog "Message: "+error.Message for each s as string in error.Stack System.DebugLog s next End
Function GetLoginTimeString() as string dim p as ProcessMBS dim d as CFDictionaryMBS dim cd as CFDateMBS dim co as CFObjectMBS dim g as CFGregorianDateMBS p=GetSystemUIServer d=cfdictionarymbs(p.ProcessInformationCFDictionary) co=d.Value(NewCFStringMBS("LSLaunchTime")) if co = nil then co = d.Value(NewCFStringMBS("LSCheckInTime*")) end if CFShowMBS d cd=CFDateMBS(co) 'cd.Handle=co.Handle 'cd.Release=true 'cd.RetainObject g=cd.AbsoluteTime.GregorianDate(SystemCFTimeZoneMBS) if Duration then dim x as new date dim g1 as integer = g.Hour * 60 + g.Minute dim g2 as integer = x.Hour * 60 + x.Minute dim gg as integer = g2-g1 return Format(gg\60,"0")+":"+Format(gg mod 60,"00") else return Format(g.Hour,"0")+":"+Format(g.Minute,"00") end if End
Function GetSystemUIServer() as ProcessMBS dim p as ProcessMBS dim m as MemoryBlock p=new ProcessMBS p.GetFirstProcess if p.Name="SystemUIServer" then Return p end if while p.GetNextProcess if p.Name="SystemUIServer" then Return p end if wend End
Sub SetTitle() dim t as string=GetLoginTimeString s.Title = t if Duration then m = new MyTimer m.Mode = 1 m.Period = 30000 end if End
Property Duration as Boolean
Property last as string
Property m as MyTimer
Property s as MyNSStatusItemMBS
End Class
Class MyNSStatusItemMBS Inherits NSStatusItemMBS
Sub Action() app.Duration = not app.Duration app.SetTitle End
End Class
Class MyTimer Inherits Timer
Sub Action() if app.Duration then app.SetTitle end if End
End Class
End Project




Links
MBS Xojo Plugins