Desktop Alias with Applescript
    Ken Ray 
    kray at sonsothunder.com
       
    Sun Dec 11 12:56:22 CST 2005
    
    
  
On 12/11/05 12:18 PM, "Shari" <shari at gypsyware.com> wrote:
> I did experiment with creating the alias with a shell() command.  Not
> being at all familiar with that, I diddled with it.  I did not find
> much good info on the net, but worked with what little I found.  I am
> totally unfamiliar with Unix commands, and using shell() inside of
> Metacard.  I'd find references to the ln command, but searched for
> many hours to find just one line of code that gave the full command
> necessary.  With my level of Unix and Shell knowledge, I need the
> Code for Dummies version of code.  Every piece of it starting with
> the exact filepath it wants.  On OSX that is so odd now.  Does it
> want the disk name?  The word "Volumes" as the beginner?  Is
> Metacards "effective filename" minus a few items to back out of the
> Contents folder enough to make it happy?  You get the idea of
> everything I experimented with...
Yeah, I can understand, Shari. Here's some basic info that should help:
1) The Terminal only understands "/"-delimited UNIX style paths (also called
"POSIX" paths), and any path that includes a space has to either be fully
quoted, or precede each space with a backslash. The nice thing is that you
can drag and drop files into the Terminal and it will put the path in for
you. Examples, to open a folder called "MC Stacks" that I have on my
desktop:
  open "/Users/kenray/Desktop/MC Stacks"
or
  open /Users/kenray/Desktop/MC\ Stacks
2) POSIX paths will include  the "/Volumes" *if* there is more than one
mounted volume, and the volume you're addressing is *not* the first drive
loaded (i.e. the one in the upper-right corner of the desktop). And if it
does so, it is in the form:
  /Volumes/<name of hard disk>
So I've got a file called "test.txt" on my backup drive. The drive is called
"Stormwinds BU" (since my main HD is called "Stormwinds"). When I drag that
file into the Terminal, it shows it as:
  /Volumes/Stormwinds\ BU/test.txt
3) AppleScript can work with *both* ":"-delimited OS 9 paths as well as
POSIX paths. If you don't specify anything, AppleScript will assume the
colon-delimited OS 9 paths. However you can get a POSIX path by doing
something like this:
  set thePath to POSIX path of myFilePath as string
> Even though I had the full pathway to the desktop, it put the alias
> one level down.  Double click on the disk icon and there's the alias.
> Not on the desktop.  Also, it did not have the nifty program icon,
> but a generic piece of paper.  Not acceptable for a program to be
> publicly distributed.  Thirdly, the danged things refuse to be
> deleted!  I created them two days ago but cannot delete them.  I
> don't recall a password to the Admin account as I've never really
> needed to use it... but am assuming that will be the only way to get
> rid of them.  That's also bad because my program has an uninstaller
> which uninstalls all files outside of the program folder including
> the desktop alias.
Don't know what happened there...
> As for using Applescript, what broke is Applescript's ability to
> create the link, not the link itself.  I know that moving a file
> after the link is created will break it :-)  But what baffled me is
> that the Applescript to create the link which worked initially,
> stopped working.  Suddenly it would not create links.  I'm 99.9999%
> certain I did not change the code.  Generally if it ain't broke, I
> don't diddle with it unless I'm improving it.  That code didn't need
> improving.  Until it broke.... :-\
Did it work in other versions of OS X, or only in OS 9?
> In searching the archives there were references to Tuviah's use of
> the ln command, but no specifics to follow.  Just a vague reference.
> I do not know if it's possible to use the ln command and keep the
> nifty icon, and make it deletable...
Whenever you want to know how to use a particular Terminal command, open the
terminal and type "man" (for "manual") followed by the name of the command.
So for "man ln", it shows this (I'm only showing a portion of the entry):
NAME
     ln, link - make links
SYNOPSIS
     ln [-fhinsv] source_file [target_file]
     ln [-fhinsv] source_file ... target_dir
     link source_file target_file
DESCRIPTION
     The ln utility creates a new directory entry (linked file) which has
     the same modes as the original file.  It is useful for maintaining
     multiple copies of a file in many places at once without using up
     storage for the ``copies''; instead, a link ``points'' to the original
     copy.  There are two types of links; hard links and symbolic links.
     How a link ``points'' to a file is one of the differences between a
     hard and symbolic link.
There's a better UI to the 'man' entries by using a program called "ManOpen"
(you can search Google for that).
In any event, when I issue:
  ln -s <srcPath> <pathToAlias>
it creates an alias, with icon, etc. So in my case, if I want to alias the
Calculator application to my desktop, I'd do this:
  ln -s /Applications/Calculator.app /Users/kenray/Desktop/Calculator
Hope this helps,
Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
    
    
More information about the metacard
mailing list