[MacOS X] finding the orig file of an alias

for the time being i'm using the finder thru AppleScript and then aeosa
in order to find the original path of an alias.

that's time consuming ))

does exist a direct rubyish way to do that (as in perl for ex.) ?

···

--
une bévue

You might be able to use RubyCocoa to do it a little more directly.

···

On Aug 2, 2006, at 9:40 PM, Une bévue wrote:

for the time being i'm using the finder thru AppleScript and then aeosa
in order to find the original path of an alias.

that's time consuming ))

does exist a direct rubyish way to do that (as in perl for ex.) ?
--
une bévue

An alias or a symlink? Symlinks should be easy, but aliases are harder.

For an alias you'll need to hook in to Core Foundation, check out this
ADC article:
http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html

···

On 8/3/06, Une bévue <pere.noel@laponie.com.invalid> wrote:

for the time being i'm using the finder thru AppleScript and then aeosa
in order to find the original path of an alias.

that's time consuming ))

does exist a direct rubyish way to do that (as in perl for ex.) ?

--
Phillip Hutchings
http://www.sitharus.com/

In my quick perusal of the ruby-doc.org site, File.readlink and File.symlink?
appear to me to satisfy the bill for determining and reading a link
(reversely respective)

···

On 8/2/06, Logan Capaldo <logancapaldo@gmail.com> wrote:

On Aug 2, 2006, at 9:40 PM, Une bévue wrote:

>
> for the time being i'm using the finder thru AppleScript and then
> aeosa
> in order to find the original path of an alias.
>
> that's time consuming ))
>
> does exist a direct rubyish way to do that (as in perl for ex.) ?
> --
> une bévue
>

You might be able to use RubyCocoa to do it a little more directly.

An alias or a symlink? Symlinks should be easy, but aliases are harder.

an alias an "apple" alias not a unix symlink.

For an alias you'll need to hook in to Core Foundation, check out this
ADC article:
http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html

fine thanks !

Yvon

···

Le 3 août 06 à 04:28, Phillip Hutchings a écrit :

thanks very much howver i've never called Cor foundation from the time being...

first, how to get the constant : "kCFURLPOSIXPathStyle" ? (I've put 0...)
second how to call the method "CFURLCreateWithFileSystemPath" ?

from ruby side.

if writing :

fm=OSX::NSFileManager.defaultManager

i get :

NameError: uninitialized constant OSX::NSFileManager

best,

Yvon

···

Le 3 août 06 à 04:28, Phillip Hutchings a écrit :

For an alias you'll need to hook in to Core Foundation, check out this
ADC article:
http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html

OK, i'm reading this article, but i'm lost on how to use some methods...

let me tell you what i've understood from the above mentionned "ResolvingAliases.html"

- 1 - convert NSURL to FSRef using CFURLGetFSRef(url, &fsRef)
- 2 - resolve alias with FSResolveAliasFile
- 3 - go back to the url side by applying CFURLCreateFromFSRef(NULL, &fsRef)

what i don't understand is on what kind of receiver i must apply the method "CFURLGetFSRef"

i seems that "OSX::NSFileManager.defaultManager" couldn't do the trick...

Yvon

···

Le 3 août 06 à 04:28, Phillip Hutchings a écrit :

For an alias you'll need to hook in to Core Foundation, check out this
ADC article:
http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html

i wasn't speaking about symling rather about true apple alias.

···

Le 3 août 06 à 03:58, Greg McWhirter a écrit :

In my quick perusal of the ruby-doc.org site, File.readlink and File.symlink?
appear to me to satisfy the bill for determining and reading a link

That's odd. I got this:

irb(main):002:0> require 'osx/aeosa'
=> true
irb(main):003:0> require 'osx/cocoa'
=> true
irb(main):004:0> fm=OSX::NSFileManager.defaultManager
=> #<OSX::NSFileManager:0x2fc3e0 class='NSFileManager' id=0x434470>
irb(main):005:0>

Did you require 'osx/cocoa'?

···

On Aug 3, 2006, at 0:53, Yvon Thoraval wrote:

from ruby side.

if writing :

fm=OSX::NSFileManager.defaultManager

i get :

NameError: uninitialized constant OSX::NSFileManager

Oh, yea, I forgot to mention that the fastest place to find answers to these questions would be on the rubycocoa-talk mailing list....

···

On Aug 3, 2006, at 0:53, Yvon Thoraval wrote:

first, how to get the constant : "kCFURLPOSIXPathStyle" ? (I've put 0...)
second how to call the method "CFURLCreateWithFileSystemPath" ?

I can't help you with calling the CF functions, the rubycocoa list
might know more

i seems that "OSX::NSFileManager.defaultManager" couldn't do the
trick...

Unfortunately Cocoa can't actually handle aliases itself, you need to
use other functions. Google for 'Cocoa alias resolve', there's a few
informative pages.

···

--
Phillip Hutchings
http://www.sitharus.com/

they have a tendancy, fo such a question, to direct me by Cocoa-Dev ))

···

Dave Howell <groups+2006@howell.seattle.wa.us> wrote:

Oh, yea, I forgot to mention that the fastest place to find answers to
these questions would be on the rubycocoa-talk mailing list....

--
une bévue

irb(main):004:0> fm=OSX::NSFileManager.defaultManager
=> #<OSX::NSFileManager:0x2fc3e0 class='NSFileManager' id=0x434470>
irb(main):005:0>

ok thanx

Did you require 'osx/cocoa'?

generally speaking yes, both of them (rubycocoa and aeosa).

but in a small trying script i might have forgot this "small detail" )))

···

Dave Howell <groups+2006@howell.seattle.wa.us> wrote:
--
une bévue

not at all, i'm sure about that ))

because, when :
require 'osx/cocoa'

i get an error within my text editor (TextMate) or at terminal :

LoadError: no such file to load -- rubycocoa
method gem_original_require
in custom_require.rb at line 27
method require
in custom_require.rb at line 27
at top level
in cocoa.rb at line 11
method require
in custom_require.rb at line 27
at top level
in read-alias.rb at line 5

when using "require 'osx/cocoa'" within XCode : no prob...

···

Dave Howell <groups+2006@howell.seattle.wa.us> wrote:

Did you require 'osx/cocoa'?

--
une bévue

fine thanx, i've found something by googleing...

this is at <http://bdistributed.com/Projects/BDAlias/&gt;

they have implemented a class following Apple's rcomandation :
<http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileM
gmt/Tasks/ResolvingAliases.html>

(that's the BDAlias#fullPath method calling #fullPathRelativeToPath:nil)

here is my little test :

require 'osx/cocoa'

OSX.ns_import('BDAlias')
f=OSX::BDAlias.alloc.initWithPath("/Users/yvon/work/RubyCocoa/MacSOUPSwi
tcher/map/read-alias/search/for/the/original/file/read-alias.pl")
p "f.class=#{f.class}"
# => "f.class=OSX::BDAlias"
p "f.fullPath=#{f.fullPath}"
# =>
"f.fullPath=/Users/yvon/work/RubyCocoa/MacSOUPSwitcher/map/read-alias/se
arch/for/the/original/file/read-alias.pl"

using BDAlias from ruby works very well however the return path isn't
the path of the file pointed by the alias rather the path of the alias
itself )))

i've compared ObjC version of BDAlias versus Apple's recomandation :
looks good...

then, i don't understand why this desapointing result...

something i misunderstood ???

···

Phillip Hutchings <sitharus@sitharus.com> wrote:

Unfortunately Cocoa can't actually handle aliases itself, you need to
use other functions. Google for 'Cocoa alias resolve', there's a few
informative pages.

--
une bévue

Hmm. I suspect if you hunt around in ~/Library/Frameworks or /Library/Frameworks, you'll find the RubyCocoa framework. Which is to say, nowhere on your command-line path directories, but exactly where Cocoa apps expect to find such things.

Based on the misery I've experienced in this situation, were I you, I would now try to wipe every last trace of RubyCocoa off my system, then do a new install in order to get *one* copy of RubyCocoa that's visible to all the different ways you can run Ruby.

If you don't wipe it first, then you can easily get in a situation where the command line is running a *different* version of RubyCocoa than XCode, and that's hideous to debug.

Trust me on that one.

···

On Aug 3, 2006, at 16:20, Une bévue wrote:

Dave Howell <groups+2006@howell.seattle.wa.us> wrote:

Did you require 'osx/cocoa'?

not at all, i'm sure about that ))

because, when :
require 'osx/cocoa'

i get an error within my text editor (TextMate) or at terminal :

LoadError: no such file to load -- rubycocoa

when using "require 'osx/cocoa'" within XCode : no prob...

Yes. The BDAlias class does not support resolving existing aliases, it allows to create alias record to provide persistent file references which can be better then simple pathnames in some cases. Just look at the source code or, even better, read the documentation, it's all explained there :>

···

On 4 août 06, at 12:45, Une bévue wrote:

something i misunderstood ???

--
Luc Heinrich - luc@honk-honk.com - http://www.honk-honk.com

i've installed ruby, rubycocoa by DarwinPorts...

right now, i've found a workaround, instead of writting :

require 'osx/cocoa' # alone

i use : require '/opt/local/lib/ruby/vendor_ruby/1.8/powerpc-darwin8.5.0/rubycocoa.bundle' before.

and it works, not a "good" solution, only to experiment apart from XCode.

what i suspect also is that the loading order of *.rb files isn't the same within XCode than using terminal...

from XCode i'm sure i'm using the same ruby as from terminal and/or Textmate (by "which ruby" giving the same "/opt/local/bin/ruby")

the RubyCocoaFramework lies in :

/Library/Frameworks/RubyCocoa.framework

it has been installed by darwinports

i've tried several times having the same setup for ruby from command line and from XCode, and i've learned today darwinports isn't the best...

what kind of install would you advice ?

from cvs sources ?

best,

Yvon

PS : on RubyCocoa list they advice me to use dp )))

···

Le 4 août 06 à 09:12, Dave Howell a écrit :

Hmm. I suspect if you hunt around in ~/Library/Frameworks or /Library/Frameworks, you'll find the RubyCocoa framework. Which is to say, nowhere on your command-line path directories, but exactly where Cocoa apps expect to find such things.

Based on the misery I've experienced in this situation, were I you, I would now try to wipe every last trace of RubyCocoa off my system, then do a new install in order to get *one* copy of RubyCocoa that's visible to all the different ways you can run Ruby.

If you don't wipe it first, then you can easily get in a situation where the command line is running a *different* version of RubyCocoa than XCode, and that's hideous to debug.

then i misunderstood also the Apple's page :
<http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileM
gmt/Tasks/ResolvingAliases.html> ???

BDAlias and this are using about the same methods.

···

Luc Heinrich <luc@honk-honk.com> wrote:

> something i misunderstood ???

Yes. The BDAlias class does not support resolving existing aliases,
it allows to create alias record to provide persistent file
references which can be better then simple pathnames in some cases.
Just look at the source code or, even better, read the documentation,
it's all explained there :>

--
une bévue

Yes, people are always telling me about the lovely powers of Darwinports/Fink/CVS/Gem and on and on. I don't believe them any more, though. (Well, RubyGems has worked reasonably well for those things that are available as gems.)

My current RubyCocoa (and Ruby 1.8.4) was installed by downloading a .tar.gz file or some such thing, and running
  ./configure
  make
  make install

Whatever that's called. Is that the best way? I have no idea. But it did let me put things exactly where I wanted them, which for me, meant that all my Ruby junk is in the highly visible /Library/Ruby, not in /usr/local/whatever or /sw/someplace or /opt/secret/hiding/spot. (Although I did get to discover that some part of the RubyCocoa installer couldn't cope with installing from a path with spaces in it. That's been fixed.)

And it seems to work, which is more than I can say for 66% of my attempted Fink installs and 100% of my DarwinPorts attempts. I haven't tried any CVS-ing yet, because I'm allergic to unripe software in general.

···

On Aug 4, 2006, at 0:36, Yvon Thoraval wrote:

i've tried several times having the same setup for ruby from command line and from XCode, and i've learned today darwinports isn't the best...

what kind of install would you advice ?

from cvs sources ?

PS : on RubyCocoa list they advice me to use dp )))