How to run a shell script to start a command in Rhino for Mac?

I would like to build a automation workflow with Alfred that allows me to:

  • type keyword in Alfred “weight”
  • Alfred initiates a shell script that tells Rhino for Mac to start the command “Volume” on the currently selected 3D model in the currently open Rhino file
  • the numeric output of that calculation should be intercepted by the shell script and
  • used in a calculation for the appropriate weight
  • the weight value is than saved to clipboard so I can paste it into an Excel sheet

Does Rhino support the two items needed (“actuate command from shell script” and “grab calculated value from Rhino”) ?

Please bear in mind that I am absolutely new to scripting and only have currently the most basic understanding about it.

is there a particular reason you need/want to use Alfred for this?

it’s possible to do this in Rhino using Python.

(that said… i’m not exactly sure what Alfred is anyway :wink: )

I use Alfred as a Spotlight replacement on all our Macs.

All I basically need is:

  • does Rhino allow for an external shell script to actuate a command?
  • can a calculated value from within Rhino be injected into the clipboard?

I have Alfred, but to be honest I haven’t spent any time with it. I usually just use AppleScript.

For your first question, no. But it can be done within Rhino with python. Which leads to your second question. I haven’t checked, I am in the process of switching to a new to me MacBookPro from my old MacPro, I have just installed Rhino, but I am just getting my python scripts ported. I believe python should be able to copy to the clipboard. I have a script that I use for something like this where it copies the weight to the Rhino Notes panel, it may be able to be converted to clipboard.

I may get a chance later this afternoon to try this out.


Yes, use xxx=rs.ClipboardText(). If a text string is inserted into the () as an argument, it is placed on the clipboard and the previous text on the clipboard is returned (if it exists). If the () is empty, it will return the text string currently on the clipboard (if it exists).


Thanks @Helvetosaur I was pretty sure it could be done.


Hey guys thanks so much for the first input :wink:

I just have found out this behavior:

  • open Rhino file

  • select 3D model to calculate the volume of

  • you can now ditch apps, work outside of Rhino

  • now focus the OS back to Rhino

  • a simple paste into Rhino of the command script “! _Volume” will trigger the volume calculation on the still selected 3D model

… hence the actuation of the volume calculation is an easy part to be done from outside of Rhino (just focus to Rhino and paste text string “! _Volume”

Here is were I am stuck:
How to separate the numerical value within the Rhino output from for example:

“Volume = 25790.0347 (+/- 1e-05) cubic millimeters”

I would like to copy just 25790.0347 to the clipboard in order to continue to use the value to calculate weights outside of Rhino.

You can just go to Command History down on the bottom left, 3 bars, I am rushing out and Rhino is not open so no screenshot, and jus copy the amount there.


fwiw, that doesn’t work on mac… @stevebaer showed this method which does work:

import clr
import Eto.Forms

cb = Eto.Forms.Clipboard()
cb.Text = "Hello From Rhino" 

Yes Randy, that is the hands on approach I am doing up to now.
My goal is to completely automate this and still being able to have some flexibility with choosing different material properties.

But: doing it all from one simply keyword from Alfred.

The final workflow I envision should be:

  • Working on a calculation in Excel.
  • open 3D model in Rhino and selecting model
  • type “weight” in Alfred + select material in Alfred

scripts are working

  • go back into Excel, selecting the proper text field
  • paste clipboard value into text field

just posting this here as an alternative route…

import rhinoscriptsyntax as rs
import math
import clr
import Eto.Forms

objs = rs.GetObjects("Select Concrete Volumes", 16, False, True)
total = 0

for obj in objs:
    if rs.IsObjectSolid(obj):
        vol = rs.SurfaceVolume(obj)
        yds = vol[0] / 46656
        weight = yds * 3800
        weight = int(math.ceil(weight))
        total = total + weight
        print str(weight) + " lbs"

rs.MessageBox("Total = " + str(total) + " lbs", 0, "Concrete Weight")

cb = Eto.Forms.Clipboard()
cb.Text = str(total)

that’s a script i use to calculate concrete weight (though the way it’s written is specifically going to calculate in Lbs per cu.yard in a template using inches as a unit… i don’t normally want the results going to the clipboard but the above example has been modified a little to do that.

1 Like

Ah, OK, thanks…

without bringing up Python again, something you may want to look into is creating a Service in instead of whatever you have going on in Alfred.

with a Service, it will create a menu item in Excel itself which can be assigned a keystroke (ie- you just use a keystroke in eXcel to trigger the shell script)

Automator has actions specifically to write various scripts within (AppleScript, shell script, javaScript)

for example, i have a Service in Rhino which i use to run scripts being written in

that was done using Automator and it’s a simple cmmd-R while in rhino to trigger.

Hey Jeff, thanks for sharing the script above!
I am having troubles with my external drives atm and am on a deadline so I will have to look at this at a later date and may have questions :wink:

Regarding the suggestion about Automator - I loved to use Automator in the past and made extensive use of it, building droplets for repetitive tasks or building “scripts” to extend OS functions.
I never used the services feature as I loathe the deep menu diving it involved (funny - I never ever thought about assigning a shortly to those services now that you mention it).

I rather not use Automator any longer if there is a more efficient way.
I just upgraded to Sierra and found that for one reason or another some of my old Automator workflows just do not run as fast any longer - in some there is now ever so slightly a longer waiting time which breaks my workflow - hence I am rolling out Automator.

Another reason why a Automator service in Excel would not be as nice is that with the operation through Alfred I will have the correct value in my clipboard allowing for using it EVERYwhere :wink:

  • quickly mail projected weight of an assembly to a customer with
  • calculate in Excel
  • note value in a journal
  • add part weight to folder name in project folder,

thats the general idea here (I do this already, just all manually :frowning:

1 Like