3

I have a Shell Script where I need to create aliases folders on a MacOSX 10.6.X so I call osascript to do it with the code below:

Source="/Volumes/Test Project/Folder/SubFolder"
Destination="/Volumes/Test Project/Dest/"

/usr/bin/osascript -e 'tell application "Finder" to make alias file to POSIX file "$Source" at POSIX file "$Destination"'

This code returns:

29:103: execution error: Finder got an error: AppleEvent handler failed. (-10000)

Does anyone have a solution?

Drew Gaynor
  • 8,292
  • 5
  • 40
  • 53
Arthur Alves
  • 458
  • 1
  • 5
  • 13

2 Answers2

5

The shell doesn't substitute variables (e.g. $Source) inside single-quoted strings (e.g. the entire AppleScript command). Solution: use double-quotes around the command (which means you need to escape the double-quotes inside it with backslashes).

/usr/bin/osascript -e "tell application \"Finder\" to make alias file to POSIX file \"$Source\" at POSIX file \"$Destination\""
Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
3

Any reason keeping you from using: ln -s "$Source" "$Destination"?

Fivesheep
  • 236
  • 2
  • 7
  • 3
    If you move a file and replace it with an identically named file, aliases to the original file now point to the new file. Similarly, if you move a file on the same volume **(without replacing it)**, aliases use the unique identity information to locate the file. If you move a file somewhere on the same volume without replacing it, **symbolic links to the file break while aliases do not**. The only way to fix a symbolic link is to delete it and create a new one. – Arthur Alves Jun 23 '12 at 01:57
  • 1
    then omit the -s option. use hard links instead – Fivesheep Jun 23 '12 at 03:39
  • 1
    thank you for being trying to solve my problem. Sometimes alias behaves as symlink and hard link, but you saw how much **smaller** it can be? Make an alias of an image with **1.7mb** (jpeg), it'll have just **~164k**. You understand why I need to make alias? – Arthur Alves Jun 23 '12 at 04:35
  • 2
    @Arthur Alves: You are confused here. A hardlink will be even smaller than a softlink, which in turn will be smaller than a Finder alias. So in fact, by creating a Finder alias, you are creating the *largest* (and also the least compatible) type of link. – username Jun 23 '12 at 13:54
  • 1
    @Arthur Alves. "symbolic links to the file break while aliases do not" is true only in theory. Finder aliases are actually quite brittle. Each Finder alias contains a kind of search path to a parent folder, which assists the OS in knowing where to look if the file is missing - this, again, is fine in theory, but in practice it leads often to broken links. – username Jun 23 '12 at 13:59
  • **Hardlinks can't be smaller** than softlinks, dear @username, you're not right! **Hardlinks have the same size** as the original files. – Arthur Alves Jun 23 '12 at 21:46
  • Yes, it will appear to have the same size as the original file... and yet I can create 100 hardlinks to a 500GB file on my 1TB harddisk without running out of space! I'll let you think about that for a while ;) – username Jun 24 '12 at 00:43
  • a hard link is another reference(or pointer) to the same file(the data). since you are using them on the same volume, it should be fine. the only limit is that you can't use it among different volume(partitions). – Fivesheep Jun 24 '12 at 01:26
  • Yes, what @Fivesheep said. The only thing that bears a mention is that you need to be careful when "updating" the contents of a hardlinked file. If /some/file.txt and /some/other.txt point to the same file, and an application updates /some/file.txt by deleting and rewriting it, the link will be "broken". If instead the app updates the file without first deleting it (by appending some data, for example) then the hardlink will not be broken. – username Jun 24 '12 at 03:50
  • Oh, yes, you're right! But, anyway, I could not use hard links because I need to create aliases of folders, not files. Thank you for your help, I learned what I thought I knew. – Arthur Alves Jun 26 '12 at 04:35