Machacks

From Madagascar
Jump to navigation Jump to search

On this page you can find a few hacks for MacOS users.


Open Vplot files with Double Click[edit]

This actually requires an application. MacOS cannot use shell scripts as applications, and the application also needs to be able to parse arguments (needed for the double click funcionality - the instigating file becomes the first argument). The below steps will turn a simple python script into an Application. First, install py2ap and then follow the below instructions (based on a website of MooSystems).

  1. Use the following python file (named ClickPen.py). Adapt the sfpen path as needed, or use an environmental variable:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""This piece of code shows how to accept 'Open Document' Apple Events in
your Python / Tk application."""

import os
import sys
import commands
import logging
import logging.handlers

# configure logging
home_dir = os.path.expanduser('~')
log_file = os.path.join(home_dir,
                        "Library/Logs/CliclPen.log")
log = logging.getLogger("main")
log.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(log_file,
                                               maxBytes=30000000,
                                               backupCount=10)
handler.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s - %(message)s')
handler.setFormatter(fmt)
log.addHandler(handler)

# callback which gets invoked when files or folders are sent to our app:
def doOpenFile(*args):
    for f in args:
        if os.path.isfile(f):
            command = '/opt/RSF/bin/sfpen %s'%(f)
            commands.getoutput(command)
        else:
            log.info("'%s' is not compatible." % f)

# when the app starts up, check for command-line arguments:
for f in sys.argv[1:]:
    doOpenFile(f)
  1. Use the following setup file (named setup.py):
"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['ClickPen.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True,
           'plist': {
                'CFBundleDocumentTypes': [{
                    'CFBundleTypeName': "File suffix of my app's documents",
                    'CFBundleTypeRole': "Editor",
                    'LSHandlerRank': "Owner",
                    'LSItemContentTypes': ["ClickPen"],
                }],
                'UTExportedTypeDeclarations': [{
                    'UTTypeConformsTo': ["public.data"],
                    'UTTypeIdentifier': "ClickPen",
                    'UTTypeDescription': "File suffix of my app's documents",
                    'UTTypeTagSpecification': {'public.filename-extension': ".vpl"}
                }],
                'CFBundleIdentifier': "ClickPen",
                'CFBundleName': "ClickPen"
            }
          }

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)


  1. Run the following command:
python setup.py py2app
  1. Now in the dist folder you should find a ClickPen.app program. Use it wisely.