Running Python scripts from alias


#1

Hi all,

This is mostly a question of not being Mac-savvy, so bear with me…

On the Mac, the “default” scripts folder is buried in your user library - about the same way it is in Windows - /Library/Application/Support/McNeel/Rhinoceros/Scripts…

In Mac, if I want to run a script in the default scripts folder I just need:
! _-RunPythonScript Scriptname

In Windows, I can do the same if I have set a search path to the folder in the Python editor; and I can also have multiple folder targets which is nice…

Now, it’s not very convenient for me who works from 3 locations and has 4 computers (3 Windows and 1 Mac mostly for checking/testing stuff) to have my scripts stored locally; my fairly extensive scripts library is in my Dropbox for access everywhere.

What I want to do is to be able to set up aliases to run scripts directly out of a specific folder in Dropbox. I can do this relatively easily on Windows, but I don’t know the correct path terminology on Mac. In Windows, if I want to run a script that is stored outside one of the standard search paths, I can simply specify the full path to the folder:

! _-RunPythonScript "D:\Dropbox\Scripts\AliasScripts\Scriptname"

So how do I specify the target similarly on a Mac…?

And, again, a wish to be able to change the default scripts folder location on Mac, as well as have multiple possible target paths…

Thanks, --Mitch


Using Object Volume
Convert closed curve to straight line
#2

OK, I got it, somehow I didn’t have something correct when I first tested, but now it works:

! _-RunPythonScript /Users/<username>/Dropbox/Folder/SubFolder/Scriptname

Glad I figured it out myself… :smile:

Will be nice if (when) we don’t have to put in the full path and can have the possibility of setting search paths as in Windows.

–Mitch


(Marlin Prowell) #3

See this article to get the path to any file as a string.


#4

Thanks Marlin, that’s helpful. I was actually using Get Info to copy the paths.

Cheers, --Mitch


#5

you should (might) be able to do this with symbolic links (not aliases)

if there’s a sym link between the rhino script folder and the Dropbox script folder, then you should be able to run the scripts the easier way (runpythonscript name)…

I’m stranded at Atlanta airport for the night… outside now enjoying the no-snow but I’ll try it out in a little bit.


#6

yeah, so that works… possibly the most confusing part about it is how to create symbolic links on mac… you can do it through terminal but i don’t know how, exactly… there seems to be a lot of instructions on it via google searching…

i used this little utility which places a ‘Make Symbolic Link’ service in the finder context menu…

it works on mavericks even though the developer hasn’t updated since 2011… tips on installing:

• download the dmg and mount it
• inside you’ll see SymbolicLinker.service and SymbolicLinker.plugin… the plugin is for leopard and older so ignore it if you’re able to run rhino on your mac.
• double-click on SymbolicLinker.service-- it will install
• if it doesn’t install, you’ll get an ‘unidentified developer’ warning and you’ll have to tell the gatekeeper to let it in:
• System Preferences-> Security&Privacy – you should see "an attempt was made to install symbolicLinker… install anyway? " answer ‘yes’ (paraphrased)

you’ll now have a ‘create symbolic link’ in the finder’s context menu (right click on a file)… if the file type has a larger context menu, the symbolic linker will be under Services


anyway, once you figure out how to make the links, the rest is easy…

• remove the Scripts folder from the rhino Applications support (or just rename it for now).
user/ Library/ Application Support/ McNeel/ Rhinoceros

• go to your dropbox folder and right-click on the folder containing your scripts.
• make symbolic link
• a new folder will appear (example symlink)
• put that new folder in your rhino app support and name it Scripts

you can now manage your rhino scripts folder from dropbox as well as run the scripts via
! _-RunPythonScript Scriptname

i think you can only run scripts which are in the top level of the scripts folder though? not positive and it may require some fiddling with if you want the folder of scripts in dropbox to have subfolders containing scripts. (as a macro-- you should still be able to nodash RunPythonScript and see/run the scripts in sub folders)


that’s probably more confusing than it needs to be and it might be simpler to just use terminal to create the links instead of dealing with the not-so-smooth install procedure for the .service… but it’s a do it once then it’s easy after that type of deal.
good luck


#7

OK, thanks for that Jeff - I think is what is needed here is that Rhino does that internally (as Windows Rhino does) so the user doesn’t have to go through this.

Cheers, --Mitch


#8

yeah- more of a proof of concept exercise I guess…

I’m pretty sure someone more code savvy could give you a one liner to paste into terminal which sets it up… if it doesn’t make it into rhinoceros.app itself.


#9

If you don’t want to install another application as Jeff said you can paste this into terminal.

  1. First delete the existing Scripts folder and empty your recycle bin.
  2. Paste this into Terminal (Change first argument to wherever you’re folder is located):

ln -s ~/Dropbox/Python/ ~/Library/Application\ Support/Mcneel/Rhinoceros/Scripts

btw thanks for bringing up this topic, until Jeff mentioned it, I had been using an alias in the default Scripts folder and going through the menu to select the script which is painful during debugging.