Getting started with OS X Leopard

M

Mark Carter

One thing I really liked about Ubuntu was that Nautilus allowed you to
add scripts to a directory which could be accessed via the RMB. It was a
very simple thing to do.

I've recently switched to Leopard, and I'm trying to do the same thing.
I'm fairly experienced with Python, but new to OS X. I have installed
FinderPop, which lets me add scripts and make them accessible via
Contextual Menus, but it is not as easy as the Nautilus way.

The sorts of things I want to do are:
* copy the directory of Finder to the clipboard
* add a new file to Finder's directory.
* find out the size of a directory
* open a file with Aquamacs, regardless of file type,

My head's swimming, though. Anyone got any really good pointers and
sample scripts that will help me work out how to achieve the sorts of
things I'm trying to do?
 
H

has

The sorts of things I want to do are:
* copy the directory of Finder to the clipboard
* add a new file to Finder's directory.
* find out the size of a directory
* open a file with Aquamacs, regardless of file type,

If you want to control desktop applications directly, that generally
means using Apple event IPC. The most popular language for application
scripting is traditionally AppleScript, but Apple event bridges exist
for other languages as well. The best of these is appscript; see my
sig for links. Some Finder scripting examples:


#!/usr/bin/python

from appscript import *
from osax import *

finder = app('Finder')
standardadditions = ScriptingAddition()

folderref = finder.Finder_windows[1].target

# set clipboard to path to front window's folder
path = folderref.get(resulttype=k.alias).path
standardadditions.set_the_clipboard_to(path)

# make new empty file in front window's folder
finder.make(new=k.file, at=folderref.get())

# get size of front window's folder
# (note: this may return k.missing_value when first run
# as Finder is sluggish at calculating folder sizes)
print folderref.size.get()

# open selected items in TextEdit
selecteditems = finder.selection.get()
finder.open(selecteditems,
using=app.application_files.ID('com.apple.textedit'))



HTH

has
 
M

Mark Carter

has said:
If you want to control desktop applications directly, that generally
means using Apple event IPC. The most popular language for application
scripting is traditionally AppleScript, but Apple event bridges exist
for other languages as well. The best of these is appscript; see my
sig for links. Some Finder scripting examples:


#!/usr/bin/python
....
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net


Aah! Many thanks. I see that I had to do
easy_install appscript
and ensure I use /usr/bin/python
I'm off to play with it now. Exciting stuff.

I installed the Python from MacPorts. That's not quite what I wanted,
because they only have a version for Python 2.4. *Sigh*. MacPorts seems
to be getting new ports all the time. The problem is, there also seems
to be an aweful lot of ports gathering bitrot.

Am I the only one to form the opinion that OS X can sometimes appear to
be a bit of a mish-mash?

I tried XCode the other day. Seemed a bit complicated, if you ask me.
I've tried to like Lisp, too. In the end, Python just rocks. I started
out with Glade a short while ago, and I'm impressed how relatively easy
it is to create GUIs and add handlers in Python.
 
A

Arnaud Delobelle

Aah! Many thanks. I see that I had to do
easy_install appscript
and ensure I use /usr/bin/python
I'm off to play with it now. Exciting stuff.

I installed the Python from MacPorts. That's not quite what I wanted,
because they only have a version for Python 2.4. *Sigh*. MacPorts seems
to be getting new ports all the time. The problem is, there also seems
to be an aweful lot of ports gathering bitrot.

Is there a particular reason you want python from MacPorts? OSX
Leopard comes with python 2.5, that's what I use on my mac.
 
M

Mark Carter

Arnaud said:
Is there a particular reason you want python from MacPorts? OSX
Leopard comes with python 2.5, that's what I use on my mac.

I heard from somewhere that Apple's version was a bit wonky, and that I
would be better off with a "proper" build.
 
K

Kevin Walzer

Mark said:
I heard from somewhere that Apple's version was a bit wonky, and that I
would be better off with a "proper" build.

Not sure where you heard that. Apple's Python is built according to Mac
guidelines (as a "framework"), but it works the same as on other platforms.
 
M

Mark Carter

if you are not satisfied with the native version, why not install the
official version directly from python site
http://www.python.org/download/ (macpython) instead of using that of
macports. It moreover is provided with many utilities

There is a macpython list that you can consult at
http://www.nabble.com/Python---pythonmac-sig-f2970.html

Thanks.

Actually, I created my first python appscript (well, "stole" it from a
previous poster is more like it) - and it's pretty cool when I combine
it with FinderPop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top