PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > OSX Finder selected files
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
OSX Finder selected files

Réponse
 
LinkBack Outils de la discussion
Vieux 22/05/2008, 17h34   #1
Mark Carter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut OSX Finder selected files

I'm new to both Ruby and OS X. What I'm aiming for is to rename some
files that have been highlighted in Finder. How do I do it? So far I've got
require 'rubygems'
require 'rbosa'

finder = OSA.app('Finder')
w = finder.window

but I'm getting
NoMethodError: undefined method ‘window’ for
<OSA::Finder::Application:0x548ee0
desc="'sign'($5343414D$)">:OSA::Finder::Applicatio n



I'm all at sea.
  Réponse avec citation
Vieux 23/05/2008, 02h34   #2
Peter Jones
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: OSX Finder selected files

Mark Carter <me@privacy.net> writes:
> I'm new to both Ruby and OS X. What I'm aiming for is to rename some
> files that have been highlighted in Finder.


,----
| require 'rubygems'
| require 'rbosa'
|
| finder = OSA.app('Finder')
|
| finder.selection.each do |item|
| # path to file, using URL notation
| puts "file=" + item.url
|
| # Rename the file
| item.name = 'new-name'
| end
`----

You can also use rdoc-osa to generate documentation for a scriptable
application:

,----
| rdoc-osa --name Finder
`----

Finally, you might want to think about subscribing to the RubyOSA
mailing list: http://rubyforge.org/mailman/listinfo/rubyosa-discuss

Good luck.

--
Peter Jones [pjones at domain below]
pmade inc. - http://pmade.com
  Réponse avec citation
Vieux 23/05/2008, 09h58   #3
hengist podd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: OSX Finder selected files

Mark Carter wrote:
> I'm new to both Ruby and OS X. What I'm aiming for is to rename some
> files that have been highlighted in Finder. How do I do it? So far I've
> got
> require 'rubygems'
> require 'rbosa'
>
> finder = OSA.app('Finder')
> w = finder.window


Scriptable Mac apps are notorious for their inadequate API
documentation, but for all its shortcomings the built-in dictionary is
still the best place to start. e.g. If you open Finder's dictionary in
Script Editor (only supports AppleScript-style formatting, but it's
already on your system), you'll see that 'window' is an element (i.e.
one-to-many relationship) of the root 'application' object, and elements
are always written in the plural in RubyOSA, e.g. w = finder.windows[0].
That said, to get the current selection, you actually need to refer to
the 'application' object's 'selection' property

BTW, note that RubyOSA no longer appears to be actively developed or
supported (I suspect Laurent has moved on to bigger and better things
since Apple decided not to include RubyOSA in Leopard). I'd recommend
using rb-appscript (see my sig) which aside from being actively
supported is better featured and more reliable than RubyOSA/SB. Example:

require 'appscript'
include Appscript

Finder = app('Finder')

Finder.selection.get.each do |ref|
ref.name.set("renamed #{ref.name.get}")
end

The ASDictionary application on the appscript website can be used to
export appscript-style application dictionaries in HTML format, and the
accompanying ASTranslate tool is very handy when you want to know how to
translate an application command from AppleScript syntax to its
appscript equivalent.

As a bonus, with ASDictionary installed, you can use appscript's
built-in # method to explore an application's dictionary
interactively, e.g.:

$ irb
>> require 'appscript'; include Appscript

=> Object
>> f = app('Finder')

=> app("/System/Library/CoreServices/Finder.app")
>> f.

================================================== ============================
(-t)

Reference: app("/System/Library/CoreServices/Finder.app")

------------------------------------------------------------------------------
Description of reference

Terminology for application class

Class: application -- The Finder
See also:
Finder Basics
Properties:
clipboard (r/o) : reference -- (NOT AVAILABLE YET) the Finder’s
clipboard
window
name (r/o) : international_text -- the Finder’s name
visible : boolean -- Is the Finder’s layer visible?
frontmost : boolean -- Is the Finder the frontmost process?
selection : reference -- the selection in the frontmost Finder
window
...
================================================== ============================
=> app("/System/Library/CoreServices/Finder.app")
>>



HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 24/05/2008, 13h48   #4
John Joyce
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: OSX Finder selected files

In addition, before going terribly far with OS X scripting outside of
AppleScript itself, you'll do well to learn some AppleScript first to
understand how it works (and how it doesn't).
Matt Neuberg's book on AppleScript will teach you a lot of what it
can and cannot do and the how and why.
Other books may be gentler introductions/tutorials and will be
useful, but Matt's explanations of the frustrations and workflow will
be very reassuring.
That said, you might be surprised how much you can pass to apps via
the command line as well...
(there's more than one way to do it in many cases)

rb-appscript will make it more convenient to pass data to/from Ruby.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h15.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13698 seconds with 12 queries