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

Create a truly transparent Activity Monitor Dock icon Apps
After reading the prior hint on faking transparency for Activity Monitor's Dock icon, I decided that I could settle for no less than true transparency. Knowing that Cocoa's NSColor fully supports it, and acting on a hunch that Activity Monitor was probably archiving the chosen NSColor into the user defaults, I decided to view the com.apple.ActivityMonitor.plist file. Lo and behold, it does. So now the only thing between me and true transparency was an archived instance of NSColor.

The method is relatively simple. First you need a way to generate the archived NSColor.

I chose to write a very simple command-line Objective-C program (transparentcolor.m) as follows:

#import <AppKit/NSColor.h>
#import <Foundation/NSArchiver.h>
#import <Foundation/NSData.h>
#import <Foundation/NSAutoreleasePool.h>

#include <stdio.h>

int main()
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	NSColor *transparentColor = [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:0.0];
	NSData *theData = [NSArchiver archivedDataWithRootObject:transparentColor];
	size_t length = [theData length];
	unsigned char *bytes = malloc(length);
	[theData getBytes:bytes];
#if 1
	size_t i;
	for(i=0; i<length; ++i)
	{
		printf("%02x", bytes[i]);
	}
	printf("n");
#else
	fwrite(bytes, length, 1, stdout);
#endif

	[pool release];
	return 0;
}

You can change the #if 1 to if 0 if you want the raw data which you can pipe through hexdump or openssl base64, depending on how you want to use it. I wanted to use it with the defaults write command, so I chose to implement the hex dumping in the program. You can compile it quite simply with the following command: gcc -framework Cocoa transparentcolor.m -- you'll need Xcode installed, of course.

This will create an executable file a.out in the current directory. Make sure Activity Monitor is not running, and then run this command:
defaults write com.apple.ActivityMonitor CPUIdleColor -data `./a.out`
Take care to notice the back ticks, which cause the shell to use the output of the ./a.out command as the argument to the -data switch.

Now fire up Activity Monitor and enjoy your new transparency. Whatever you do, don't try to change the idle color, because this will immediately cause the alpha value to change to 1.0 instead of the fully transparent 0.0. I have not tried other combinations, but it should be possible to do a semi-transparent color if desired. A better program would have contained its own ability to change Activity Monitor's defaults, and would accept command-line options for the color values, but this one was just a quick hack. Hope you like it.

[robg adds: I tested this, and it works as described. Note that it will also affect the icon you see in the Command-Tab switcher, as Activity Monitor seems to accomplish its tricks by changing the actual application icon when you tell it to display a usage chart of some sort as its Dock icon.]
    •    
  • Currently 3.40 / 5
  You rated: 5 / 5 (5 votes cast)
 
[13,148 views]  

Create a truly transparent Activity Monitor Dock icon | 11 comments | Create New Account
Click here to return to the 'Create a truly transparent Activity Monitor Dock icon' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a truly transparent Activity Monitor Dock icon
Authored by: jic2000 on Aug 08, '07 08:12:36AM

When I put "defaults write com.apple.ActivityMonitor CPUIdleColor -data `./a.out`" in the Terminal, it just gives me the standard output as if I had typed "defaults" and nothing else. I copied and pasted from the hint, so I know I didn't mistype anything. Is it something wrong with my comptuer?

When I run a.out by itself, it gives me this output:
040b747970656473747265616d8103e8840140848484074e53436f6c6f72008484084e534f626a6563740085840163018404666666660000000086n
I have no idea what that means, but I figured it might help to figure out my problem.



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: myrkr on Aug 08, '07 08:51:15AM

Same thing here.

I have narrowed it down to the 'n' at the end of the string. 'n' is not a hex character, I think it should be a '\n'. That made it work for me.

It also works when I change '#if 1' to '#if 0' and remove the '-data' option.



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: jic2000 on Aug 08, '07 09:00:12AM

Well, both of those made the command execute without an error, but my icon is still opaque.



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: NB on Aug 08, '07 09:05:05AM
Well, since you ran it for us, all we have to do know is:
defaults write com.apple.ActivityMonitor CPUIdleColor -data 040b747970656473747265616d8103e8840140848484074e53436f6c6f72008484084e534f626a6563740085840163018404666666660000000086
(single line)
Actually, I had to go in Activity Monitor before and change the colors once to make it work. I guess Activity Monitor stores another "hascustomcolor" setting.

[ Reply to This | # ]
Change "n" to "\n"
Authored by: dfe on Aug 08, '07 09:31:12AM

As anoher poster here has noted, Geeklog somehow munged the C source in an odd way and changed the last printf("n") (prints a newline) to printf("n") (prints a literal letter n). Just in case geeklog munges this post that is double-quote backslash n double-quote.

I also noticed that another poster here decided that if you change the if 1 to if 0 then it goes back to the original code I wrote that dumps it out as raw binary data. This can then be used as the argument to defaults write if you don't use the -data flag which causes the defaults command to use the data as is. Your mileage may vary on that one though.



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: robogobo on Aug 08, '07 02:50:24PM

um, why would I want this? and doesn't printf("n")=printf("n")?



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: avox on Aug 09, '07 09:54:00AM

Note the backslash '\\' seen in the subject line above. Obviously it gets filtered out in the body text of posts.



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: avox on Aug 09, '07 10:03:25AM

In fact I couldn't get myself to compiling an Objective C program, so I just opened the file ~/Library/Preferences/com.apple.ActivityMonitor.plist in the propertylist editor and changed the last bytes of the CPUIdleColor entry to "66660000 000086". Works like a charm.

For some reason the background in the Activity Monitor window is still black, but I prefer it that way anyhow...

Ah yes, and make sure to shut down Activity Monitor before you do this.

/Andreas



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: Fairly on Aug 12, '07 09:15:11AM

You've got a printf("n") there. You want a printf("\n").



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: Fairly on Aug 12, '07 09:19:59AM

You don't need all those includes either. All you need is Cocoa/Cocoa.h and stdio.



[ Reply to This | # ]
Create a truly transparent Activity Monitor Dock icon
Authored by: dfe on Aug 13, '07 09:34:03AM

It is true that you can use #import <Cocoa/Cocoa.h> in preference to including needed headers separately. If you have a large project with many source files this makes sense as you can put that import in your prefix header and precompile it.

When you have only one source file there is no advantage to using precompiled headers and including every Cocoa header forces the compiler to parse an awful lot of code that will never be used. Therefore, when writing small programs that live in only one source file my preference is to import only the needed headers.



[ Reply to This | # ]