Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / March 2008



Tip: Looking for answers? Try searching our database.

Mac OS alias from Perl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan Neville - 09 Dec 2007 00:01 GMT
Hello,
Does anyone know how to make a Mac OS alias in Perl?  So, I wish to
have Perl create aliases in multiple directories rather than copy the
original file.

Thanks,
Dan
--
Celeste Suliin Burris - 09 Dec 2007 00:06 GMT
Use a symbolic link instead.  Perl handles those natively, and they can be
accessed from the command line. The Finder just treats them the same as
aliases.

> From: Dan Neville <dneville@nytimes.com>
> Date: Sat, 8 Dec 2007 19:01:46 -0500
[quoted text clipped - 9 lines]
> Dan
> --
Chris Devers - 09 Dec 2007 02:19 GMT
On Dec 8, 2007, at 7:06 PM, Celeste Suliin Burris <csburris@earthlink.net
> wrote:

> Use a symbolic link instead.  Perl handles those natively, and they  
> can be
> accessed from the command line. The Finder just treats them the same  
> as
> aliases.

Not quite. I forget the details at the moment, but Finder aliases are  
kind of like "firm links": while hardlinks point to inodes, and  
softlinks point to file pathnames, aliases point to the logical file  
in a more robust way than symlinks. For example, if the reverent file  
moves, symlinks break, but aliases shouldn't.

If you really want aliases, I think the CPAN modules of Dan Kogai and  
Chris Nandor are the place to start. I forget who wrote what, but  
modules like (I think) MacOS::File and Mac::Glue can either make the  
right calls directly, or leverage Applescript / OSAscript to do this  
for you.

Or if symlinks/softlinks are enough, just use the traditional Perl /  
Unix methods to make those.

Signature

Chris Devers

Dave Gomez - 09 Dec 2007 04:46 GMT
For the traditional method if you can't find a module or common method  
just use the quote below the tilde, ie `ln -s /path/to/my/interest /
path/to/my/alias`, note if this will run in a cron, you will have to  
give the full path ot ln, just do a "whereis ln" command (mine and  
yours should be in /bin.

Dave

> On Dec 8, 2007, at 7:06 PM, Celeste Suliin Burris <csburris@earthlink.net
> > wrote:
[quoted text clipped - 19 lines]
> Or if symlinks/softlinks are enough, just use the traditional Perl /  
> Unix methods to make those.
Michael Barto - 09 Dec 2007 20:47 GMT
Yes the alias function in MacOSX is different than regular Unix. If your
software is targets a Unix server and not to only run under MacOSX, it
is much better to make the links on the Mac at the command line with
Unix ln command (e.g. ln -s -which is safer) to test and maintain a
consistent Unix environment. Fortunately Mac support of regular Unix is
really excellent and ln works as advertise on a Mac. By the way, another
"got-you" is the Mac filesystem.  On new Mac computers where the
software is pre-installed, the filesystem ignores case. The is not true
in regular Unix. For example: in regular Unix, a file name like
"johnsfile" and "johnsFile" are considered different file. But on the
Mac,  they are considered the same. But you have a true Unix filesystem
by reformating the disk to support case sensitive file naming. This has
hurt me several times till I reformated my drive.

>> Use a symbolic link instead.  Perl handles those natively, and they
>> can be
[quoted text clipped - 15 lines]
> Or if symlinks/softlinks are enough, just use the traditional Perl /
> Unix methods to make those.

Signature

------------------------------------------------------------------------
*Michael Barto*
Software Architect

    LogiQwest Circle
LogiQwest Inc.
16458 Bolsa Chica Street, # 15
Huntington Beach, CA  92649
http://www.logiqwest.com/

           mbarto@logiqwest.com <mailto:mbarto@logiqwest.com>
Tel:  714 377 3705
Fax: 714 840 3937
Cell: 714 883 1949

*'tis a gift to be simple*
------------------------------------------------------------------------
This e-mail may contain LogiQwest proprietary information and should be
treated as confidential.

Peter N Lewis - 09 Dec 2007 11:11 GMT
>Does anyone know how to make a Mac OS alias in Perl?  So, I wish to
>have Perl create aliases in multiple directories rather than copy
>the original file.

There actually is no API call to create an alias file.

You can do it in Perl as described at

<http://use.perl.org/~pudge/journal/10437>

Alternatively, you can make a new alias via AppleScripting the Finder as:

set thaAlias to "Harddisk:Users:peter:thefile.cpp" as alias

tell application "Finder"
    set f to make new alias file at desktop to thaAlias
end tell
f

Which will return the alias file created.

Enjoy,
   Peter.

Signature

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>

Doug McNutt - 09 Dec 2007 19:30 GMT
>>Does anyone know how to make a Mac OS alias in Perl?  So, I wish to have Perl create aliases in multiple directories rather than copy the original file.
>
[quoted text clipped - 11 lines]
>    set f to make new alias file at desktop to thaAlias
>end tell

If you're not into the O-O stuff involved with the AppleScript modules, and you're not in a hurry, it's possible to invoke the osascript tool from within perl using backticks. You can create a string of AppleScript commands to pass to it with simple perl concatenations like ".=" or you can use a << "here" document with perl's here or with shell's here depending on how you set the backticks.

Test your AppleScript code with Script Editor first.

Using Finder is pretty much required because Finder "owns" the specification for an alias file. I have never seen a formal description of that or, for that matter, an alias resource. They are based on the file-id number which never repeats as files are created on a partition but there is more to it because that doesn't always work. Aliases do survive a file name change by the user and they use volume names so that Finder can request a floppy by name if an old alias pops up. What can cause an alias to fail is an editor that always writes the changed file to a newly created copy and then changes the names around so the original becomes the backup. The alias will point to the original while a symbolic link will point to the new.

Signature

Applescript syntax is like English spelling:
Roughly, though not thoroughly, thought through.

Chris Nandor - 12 Mar 2008 06:58 GMT
> >Does anyone know how to make a Mac OS alias in Perl?  So, I wish to
> >have Perl create aliases in multiple directories rather than copy
[quoted text clipped - 16 lines]
>
> Which will return the alias file created.

Also, you can do:

  use Mac::Glue ':all';
  my $finder = new Mac::Glue 'Finder';
  print $finder->make(
     new => 'alias',
     at  => $finder->prop('desktop'),
     to  => $finder->obj(file => "/Users/peter/thefile.cpp")
   # or:
   # to  => $finder->obj(alias => "Harddisk:Users:peter:thefile.cpp")
  );

Signature

Chris Nandor                      pudge@pobox.com    http://pudge.net/
Open Source Technology Group       pudge@ostg.com     http://ostg.com/

Brian D Foy - 10 Dec 2007 03:39 GMT
[[ This message was both posted and mailed: see
  the "To," "Cc," and "Newsgroups" headers for details. ]]

> Hello,
> Does anyone know how to make a Mac OS alias in Perl?  So, I wish to
> have Perl create aliases in multiple directories rather than copy the
> original file.

I've now create MacOSX::Alias based on Chris's code. It's on CPAN as a
developer release right now.
Dan Neville - 13 Dec 2007 15:14 GMT
Thank you to all!
I have been out sick, that is my excuse for the slow response.  I
tried to e-mail a couple of you in this group directly but I was
rejected as SPAM.  I guess, we send out a lot od e-mail...

Thank you again!

Dan
--
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.