• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
make new alias -- weird behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

make new alias -- weird behavior


  • Subject: make new alias -- weird behavior
  • From: Joel May <email@hidden>
  • Date: Tue, 15 Feb 2011 08:04:43 -0600

I need to programmatically create an alias file:

/Library/Application Support/MyCompany/MyProduct/doodle.tag alias

that points to

/Applications/MyProduct/doodle/doodle.tag

Using an alias makes it easy to redirect the doodle folder elsewhere.  I also like the robustness of aliases compared with symbolic links -- if the target folder is moved, the link usually survives.

We've used this mechanism in our product since OS8 and it's worked really well.  The alias is created during the install.  Until now, we've been using InstallerVise, but would like to move to PackageMaker.

The only way to create the alias is to use AppleScript talking with Finder.  

Here's the code:

tell application "Finder"
    set macSrcPath to POSIX file "/Applications/MyProduct/doodle/doodle.tag" as text
    set macDstFolder to POSIX file "/Library/Application Support/MyCompany/MyProduct" as text
    make new alias at folder (macDstFolder as text) to (macSrcPath as alias) with properties {name: "doodle.tag alias"}
end tell

This usually works, but it occasionally fails.  Here's what happens:

During development, I often drag a copy of the MyProduct folder to the trash and install a new copy.  If a copy of the product is in the trash, the above code will point the alias at the version of the file in the trash, not the one in the Applications folder.  In cmd-Info, Original is:

/Users/me/.Trash/MyProduct/doodle/doodle.tag

Of course, it should be:

/Applications/MyProduct/doodle/doodle.tag

I cannot figure out how to make it point to the correct file.  The above code specifies the path explicitly.  If I add 

display alert macSrcPath

to the above code, it displays 

Macintosh HD:Applications:MyProduct:doodle:doodle.tag

so the source variable is correct.

I've tried changing the last line to:

    make new alias at folder (macDstFolder as text) to (macSrcPath) with properties {name: "doodle.tag alias"}

(I removed 'as alias' after macSrcPath).  This made no difference.  Same weird behavior.

Of course, if I create the alias manually, it works fine.

If I empty the trash, it works fine.

Leaving this problem in the product will cause tech support headaches.   Does anyone know how to get 'make new alias' to always point to the file it is supposed to point to?

Thanks,
Joel May

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: make new alias -- weird behavior
      • From: Axel Luttgens <email@hidden>
    • Re: make new alias -- weird behavior
      • From: Jan Bultereys <email@hidden>
    • Re: make new alias -- weird behavior
      • From: Luther Fuller <email@hidden>
  • Prev by Date: Re: read stored variables in run only script application
  • Next by Date: Re: make new alias -- weird behavior
  • Previous by thread: Re: read stored variables in run only script application
  • Next by thread: Re: make new alias -- weird behavior
  • Index(es):
    • Date
    • Thread