By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Getting started with OS X Leopard

P: n/a
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?
Mar 15 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
has
On 15 Mar, 18:05, Mark Carter <m...@privacy.netwrote:
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
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
Mar 15 '08 #2

P: n/a
has wrote:
On 15 Mar, 18:05, Mark Carter <m...@privacy.netwrote:
>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
....
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.
Mar 15 '08 #3

P: n/a
On Mar 15, 7:31*pm, Mark Carter <m...@privacy.netwrote:
has wrote:
On 15 Mar, 18:05, Mark Carter <m...@privacy.netwrote:
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

...
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.
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.

--
Arnaud

Mar 15 '08 #4

P: n/a
Arnaud Delobelle wrote:
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.
Mar 15 '08 #5

P: n/a
Mark Carter wrote:
Arnaud Delobelle wrote:
>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.
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.

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
Mar 15 '08 #6

P: n/a

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
Mar 15 '08 #7

P: n/a
ma***********@gmail.com wrote:
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.
Mar 15 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.