Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Put the date in the menubar Desktop
Inspired by the "internationalize your menubar clock date" hack, here's the "put the date right in your menubar" hack.

It effectively changes the "show the day of the week" option for the menubar clock to "show the day of the week and date". For example, mine now says "Mon Nov 26 2001 5:40 AM"

Here's how to do it ... (if you're cautious, back up Clock.menu or just Clock)
  1. Fire up Terminal
  2. cd /System/Library/CoreServices/Menu\ Extras/Clock.menu/Contents/MacOS/
    sudo perl -p -i -e "s/%a /%x /" Clock
  3. type in your admin password, obviously, for 'sudo'. If you are typing by hand, be extra sure to include the space after "%a" and the space after "%x".

  4. Logout and back in (or kill SystemUIServer, if you're into that sort of thing).
Voila! Make sure that the "Show the day of the week" option is checked in System Preferences/Date & Time/Menu Bar Clock. Unfortunately, because it's such a low-level hack, there's no straightforward way to change the format of the date.

To put it back, change to the same directory and do:
sudo perl -p -i -e "s/%x /%a /" Clock
This is tested to work under 10.1.1. It should work fine on other versions, but no guarantees.

Eden
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[9,738 views]  

Put the date in the menubar | 14 comments | Create New Account
Click here to return to the 'Put the date in the menubar' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Very Nice :-)
Authored by: Embro on Nov 26, '01 02:59:02PM

Two questions:
1. How does this work? What is the Perl line doing?

2. I can remember the year {usually}. Can I make it just show the Day, Month, Date, time?



[ Reply to This | # ]
thanks :)
Authored by: trevden on Nov 26, '01 08:33:39PM

There's a hardcoded string ("%a ") in the Clock binary that, when fed to the equivalent of strftime(), produces the day of week string. The one-line perl script just changes the only occurrence of "%a " to "%x ", which instead produces the long date string you end up seeing.

Unfortunately, because the string is hard-coded, you can't make it any longer, so you're limited to three characters, or only one date macro. %x is by far the most useful. %e will produce only the day of the month, which might also be useful to you, though it looks a little odd.

The AM/PM text can be changed to a single macro in a similar manner. (If you're interested, go edit the binary by hand, don't try to perl it. :)

Eden




[ Reply to This | # ]
Great menu tip!
Authored by: RichB on Dec 05, '01 01:43:47AM

Thanks for something that was always missing from OS 9! I hated having to click the time just to see the date. Desktop Calendar is nice but usually hidden behind open windows.

To conserve valuable menu bar real estate I have gone to the really abbreviated day of the month format (%e). The day number toggles on and off with the preference setting for "Show day of the week" as expected. It would be nice to also see the day of the week. I don't understand why the weekday doesn't show with this date macro.

In other words, originally it was "Tues 11:00" and then with changing %a to %x it became "Tues Dec 04 2001 11:00". Now changing %x to %e it is simply "4 11:00". It seems odd the weekday is included with %x.



[ Reply to This | # ]
Details, Details, Details!!!!!
Authored by: TeeGate on Nov 26, '01 09:03:22PM

It sounds like a great tip, but as usually happens with people who are experienced with the Terminal they are vague with instructions. Put a little more detail into instruction #2 and #3.

If I copy and Paste the below text into the Terminal it doesn't ask for my password. The one time it did I was denied. Line 3 mentions to put my password in place of sudo...when???

It is frustration to think that someone would pass this tip on and not tell the reders EXACTLY how to do it.


cd /System/Library/CoreServices/Menu Extras/Clock.menu/Contents/MacOS/
sudo perl -p -i -e "s/%a /%x /" Clock



[ Reply to This | # ]
Finally
Authored by: TeeGate on Nov 26, '01 09:49:24PM

After the 50th try it just worked.

The Terminal is just Windows in disguise!!!



[ Reply to This | # ]
Finally
Authored by: freeandunmuzzled on Nov 28, '01 03:20:13AM

uhhhh no.. it's just UNIX in an apple t-shirt.



[ Reply to This | # ]
Details, Details, Details!!!!!
Authored by: rzdroj on Nov 26, '01 10:06:17PM

When I did it, I copied and pasted one line at a time. There was an error in the first command.

cd /System/Library/CoreServices/"Menu Extras"/Clock.menu/Contents/MacOS/ should work.

NOTE: You need to put the quotes around Menu Extras before pressing return or you will get an error about "too many arguments". Unix doesn't like spaces in file names.

Earlier today, I copied the cd line just as you have shown it but noticed that it has been changed from <.../Menu Extras/...> to <.../Menu<Backslash> Extras/...> after I tried the earlier version.

Further, when I previewed my comment after typing a backslash rather than the word <backslash>, no backslash appeared in the preview version! That may be the root of the problem. Perhaps robg could let us know how to get a backslash character to appear.

Then:
sudo perl -p -i -e "s/%a /%x /" Clock

Then hit return, type in your password, and follow the rest of the instructions. You might be able to copy and paste both lines at once provided that you correct the directory name with a space using either of the two methods.

It's a nice addition to the menu bar.






[ Reply to This | # ]
Details, Details, Details!!!!!
Authored by: TeeGate on Nov 27, '01 05:18:08PM

As you say it is a nice addition. Thanks for the reply and the help.

I was tired and frustrated when I posted last night. Looking at it today my post seems harsh. I apologize to the author.

Guy



[ Reply to This | # ]
backslashes
Authored by: robg on Nov 27, '01 07:15:27PM

There's an annoying glitch in the Geeklog (the engine for the site) comment/hint parser. Any backslash is immediately eliminated when previewed. So you can try to trick it by using the HTML code for a backslash - "& # 092;" (entered without the spaces). Make sure you post in HTML mode. However, there's a second glitch -- after previewing, you'll see that the HTML code in your original post has been converted to a backslash, which will be eliminated if you preview again. So you have to remember to re-type the HTML code. The easiest way to do this is to copy all the text in the input box and just re-paste it after previewing.

So to get this backslash: \ to appear, I had to type in its HMTL code into my 'final draft' comment, and then NOT preview the comment but submit it right away. Quite frustrating! Which leads me to my question -- if there are any mySQL/PHP/regex experts that would like to take a look at the parser, please let me know! :-)

-rob.



[ Reply to This | # ]
Format String is just plain C
Authored by: Big Mac Sneep on Nov 27, '01 10:15:08AM

The %x and %a specifiers are date format specifiers from the strftime function in C.

If you have the developer tools installed, try the command (from the terminal) `man 3 strftime' (no quotes). This gives you a list of options for strftime. Be _VERY_ careful befor hacking away though: if the file you're editing is a binary file (which is not unlikely, given the path) then you can only replace "%a " with "%. ", where . represents a single character. If the file is a script, or an xml file, then you can probably edit it by hand and insert a longer string.

Right now I'm not at my OS X machine, so I cannot test it. As always: use at your own risk...

Maarten



[ Reply to This | # ]
To change the date format in the drop down menu:
Authored by: Tom_H on Jun 09, '02 08:23:24PM

This string is stored in /System/Library/CoreServices/Menu Extras/Clock.menu/Contents/Resources/English.lproj/Localizable.strings
You need to change the value for MBC_DATETIME_MENUITEM_FORMAT.
The default value is "%A %1m/%e/%Y %1I:%M%p"
I changed mine to "%A %e/%1m/%Y %1I:%M%p", which displays the date in DD/MM/YYYY format, instead of MM/DD/YYYY.
If you do it once using PropertyListEditor (part of Dev Tools), the file is changed from it's old format to an xml property list. After that you can editi it easily using pico.
Easiest way to do it is to log in as root, make the change using PropertyListEditor, then log back in as yourself. (You have to log out to see the change).
Oh, and before you start, make a backup, just in case:

cd /System/Library/CoreServices/Menu Extras
sudo cp -R Clock.menu ClockOld.menu


[ Reply to This | # ]
To change the date format in the drop down menu:
Authored by: Tom_H on Jun 09, '02 08:29:23PM

This string is stored in /System/Library/CoreServices/Menu Extras/Clock.menu/Contents/Resources/English.lproj/Localizable.strings
You need to change the value for MBC_DATETIME_MENUITEM_FORMAT.
The default value is "%A %1m/%e/%Y %1I:%M%p"
I changed mine to "%A %e/%1m/%Y %1I:%M%p", which displays the date in DD/MM/YYYY format, instead of MM/DD/YYYY.
If you do it once using PropertyListEditor (part of Dev Tools), the file is changed from it's old format to an xml property list. After that you can editi it easily using pico.
Easiest way to do it is to log in as root, make the change using PropertyListEditor, then log back in as yourself. (You have to log out to see the change).
Oh, and before you start, make a backup, just in case:

cd /System/Library/CoreServices/Menu Extras
sudo cp -R Clock.menu ClockOld.menu


[ Reply to This | # ]
To change the date format in the drop down menu:
Authored by: Mara on Jun 10, '02 09:04:31AM

I did try that, changing that line in the Localizable.strings file but it didn't work, and now in the pulldown menu the "open date and time..." command shows the following line from the file itself, ie. "/*1st menu etc.". No crashes, everything works as before, but how can I fix that? (I didn't do the backup, erm!)



[ Reply to This | # ]
Not in Panther
Authored by: Apollo18Pnut on Oct 28, '03 01:04:35PM

It probably goes without saying, but this doesn't work in Panther. The line in Localizable.strings is still there, but this hint just doesn't work.



[ Reply to This | # ]