[PYTHON] Make the OS X mouse pointer translucent

Since the mouse pointer usually only hits the tip, I thought it would be better to make it transparent. In particular, I make the pointer larger than usual, so when I put the pointer on a link etc., I sometimes have trouble seeing the letters below.

non-transparent.png

I thought that if the pointer was translucent, it would be comfortable to read the letters below even if the mouse pointer was made so huge.

The overall flow for making the mouse pointer translucent is as follows.

  1. Dump the current mouse pointer data with Mousecape
  2. Read the mouse pointer data with a Python script and make it translucent
  3. Read the data processed by Python
  4. Install Helper Tool to activate Mousecape at computer startup
  5. Register AppleScript to start up to fill the Mousecape bug

Preparation

To carry out the content of this article, you will need the following:

Mousecape is a tool for easily changing the mouse pointer. I will download and use the latest version 0.0.5.

Unzip the downloaded file and open the app file that appears, and the following window will appear.

スクリーンショット 2015-03-16 17.08.10.png

Dump the current mouse pointer

Click ** Capes-> Dump Cusros .. ** on the toolbar to dump the current settings. When completed, it will look like this:

スクリーンショット 2015-03-16 17.15.43.png

Right-click on this blue area and select ** Show in Finder ** to see the dumped cape file in the Finder, copy it to get the cape file. This becomes clear when you open it with a text editor, but inside it is a huge XML file that stores the image of the mouse pointer in Base64 encoding.

Make the mouse pointer translucent

Run the Python script that processes the cape file you just got. However, this Python script requires the following libraries:

$ pip install Pillow

You can install it with.

Then save the following script somewhere.

convert.py


from base64 import decodestring, encodestring
from xml.etree.ElementTree import ElementTree
import sys
import io
from PIL import Image

inputfile  = sys.argv[1].strip()
outputfile = sys.argv[2].strip()
opacity    = sys.argv[3].strip()

tree = ElementTree()
tree.parse(inputfile)

imagedata = tree.findall("dict/dict/dict/array/data")

for i in imagedata:
    img = decodestring(i.text)
   
    img  = Image.open(io.BytesIO(img))
    img  = img.convert('RGBA')
    data = img.getdata()

    new = []
    for p in data:
        new.append((p[0], p[1], p[2], int(p[3] * opacity)))

    img.putdata(new)
    img.save('temp.png', 'PNG')
    
    result = open('temp.png', 'r')
    base64 = encodestring(result.read())
    result.close()

    i.text = base64

tree.write(outputfile)

Execute as follows.

$ python convert.py /path/to/dumpfile.cape output.cape 0.5

This script takes command line arguments like this:

First argument
Dumped cape files
Second argument
Output destination file path
Third argument
Transmittance (0 to 1)

After waiting for a while, a file such as output.cape will be created.

Read the processed data with Mousecape

Click ** File-> Import Cape ** on the toolbar to import the cape file you just generated. It looks like this:

スクリーンショット 2015-03-16 17.37.48.png

You can delete the dumped truck at this point. You can remove it by right-clicking and ** Remove **. Then select the transparent one, right-click and select ** Apply ** to apply.

Install Helper Tool

Install the Helper Tool to make the mouse pointer transparent when the computer starts up. You can start Mousecape and install it from the toolbar with ** Mousecape-> Install Helper Tool **.

Mousecape bugs and their complements

I made the mouse pointer larger, but when I restarted it returned to its original size. It seemed difficult to analyze the source code and find the bug from now on, so I made an AppleScript to increase the size and started the script when logging in to the computer to avoid it.

set_cursor_size.scpt


tell application "Mousecape"
	activate
end tell

delay 0.1

tell application "System Events" to tell application process "Mousecape"
	click (menu item 3 of menu 1 of menu bar item 2 of menu bar 1)
	set theSlider to slider 1 of window 1
	set value of theSlider to 3.0
end tell

quit application "Mousecape"

You can change the size by replacing the 3.0 part with your favorite number. Paste this code into a script editor and export it as an application with ** File-> Export ** from the toolbar and save it in a suitable location. When executed, Yosemite will ask for permissions as follows:

スクリーンショット 2015-03-16 17.55.50.png

Open system preferences and grant permissions.

スクリーンショット 2015-03-16 17.56.55.png

Then select ** System Preferences-> Users & Groups-> Login Items ** to register the application so that it runs at startup.

スクリーンショット 2015-03-16 18.00.24.png

Summary

I think this will make the mouse pointer translucent. I've only tried it on Yosemite, so maybe it won't work on other versions.

semi-transparent.png

Recommended Posts

Make the OS X mouse pointer translucent