Giter Site home page Giter Site logo

droplet_maker's Introduction

Droplet Maker

Droplet Maker is a BBEdit package for making simple droplets/applets from a shell script. Anything with valid a shebang. Perl, Python, Ruby, PHP etc.

So it turns a target script named Make Report.py into Make Report.app.

My definition of applet is an app that performs a simple ‘script’ like action when double clicked. Usually taking a file or files as input.

A droplet takes a file or files as input when they are dropped on it’s icon.

Though there are other, better solutions; Automator.app, Shortcuts.app, or Platypus.app, I wanted to easily use source-control along with other workflow nicesties & features I’ve become accustomed to in BBEdit.

Copy & pasting a script into an Automator action really sucks after a while.

I tried to make this a little more robust then the finicky little package that I’ve been using for a while. I’m sure that there are a thousand edge cases that I haven’t thought of. Give it a try but keep in mind this is not a professional solution.

Working with this Project

  1. Clone this repository to a safe place.

  2. Run rake install from the command line while in the repository directory.

Rake Commands

rake install This installs this project as a BBEdit package in ~/Library/Application Support/BBEdit/Packages/ as Droplet Maker.bbpackage.

rake uninstall Removes the package.

rake test:cleanup Removes the build/ directory & the file droplet_script.applescript from the projects test/ directory.

Use

This package only works with a BBEdit project. The project must have a root directory. More specifically the directory that houses your target script (a.k.a. Make Report.py) must be the first item in the project.

BBEdit “insta” projects -which are made by dropping a project’s directory on the BBEdit icon- are also supported.

This package consists of two commands, Setup & Build.

You are meant to run Setup once & Build after you make changes.

Setup

Setup makes a build/ directory & a file named droplet_script.applescript.

The build/ directory is the where your applet is saved when you run Build.

The droplet_script.applescript defines the input of the final applet or droplet. I tried to define some helpful and sane defaults but you likely want to edit this file.

By default droplet_script.applescript is setup to act as a droplet & applet which ask for file(s) after being launched.

It includes these five AppleScript handlers.

  • on run
    Commands in this handler run when you double click the applet. By default it asks for files via a dialog box & runs the target script with the file paths as parameters.

    If you want to define a different kind of input, such as a user provided string, that would likely happen in this handler.

  • on open
    This is what happens when a file is dropped on the droplet icon. It’s default setup works just like on run, except the files are passed in through the drop\_files parameter.

    Either on run or on open must be present. Both are available by default, allowing the script to be an applet & droplet.

  • on run_shell_script
    This handler is called from both on run & on open. It calls your target script. It takes a string as a space separated parameter list. It then passes this string to your target script as if it’s a shell command (it’s in fact calling an executable copy of your script from inside the app bundle).

    It is required.

  • on format_params
    This is a “helper” called by both on run & on open. It takes a list of AppleScript file objects & returns a string containing the files paths. It also included a path to the applets enclosing directory by calling the on path_to_app handler.

    You can easily edit on format_params to make that optional.

  • on path_to_app
    This handler takes a sting, & appends the path to the applets parent directory. So it takes the parameters defined earlier for the target script & adds the path back to the applet to the end of the string.

Build

Run the build command while your target script is selected. If it is not selected you will get an error. It will create a an app bundle with the same name as the selected target file but with the .app extension in build/.

It is actually using droplet_script.applescript as a parameter for osacompile to make the app bundle in the build/ directory. Your target script is made into an executable & copied into the app bundle. You can find it & it’s AppleScript companion in /Project Folder/build/Project.app/Contents/Resources/Scripts/.

  • main.scpt is is the “compiled” version of droplet_script.applescript.

  • shell_script is an executable copy of your target script.

Build will also look for a image called icon.png in your project directory. It will use this image, which should be 1024 by 1024 pixels, to make a custom icon for your applet or droplet.

Icon.png is not required. MacOS will provide a default icon.

Test Directory

If you want to make changes to your copy of Droplet Maker, I suggest making a BBEdit project file for it.

Droplet Maker will check if it is being called from a project called Droplet Maker. If this is the case it will use this directory as the project root directory. Setup & Build will run from here.

It includes a test icon icon.png, a target script Test Me.rb & text file to test if an incorrect file is selected no_shebang.txt.

These files represent something pretty close to minimum requirements for Droplet Maker to work.

This is most useful if you are making changes to the package. It is also a good way to give Droplet Maker a dry run.

Etc.

I used Droplet Maker for this little Finder button app. It may be helpful as a simple example.

droplet_maker's People

Contributors

ciidub avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.