Need help with bash script - symlink problems

Discussion in 'Mac Programming' started by Poeben, Sep 14, 2007.

  1. Poeben macrumors 6502

    Jul 29, 2004
    I've been trying to get a script working that will do the following things:

    1. Create a new folder everyday, on startup, with that day's date as the folder name. (The easy part)
    2. Create an alias (or rather update the existing alias) on the desktop that points to this newly created folder. (this is what I can't figure out)
    3. Only create the folder once in a day (seems to work ok)

    So far I am able to create the folders ok, and even with multiple reboots it still seems to work, as if the folder exists I won't create it again. The problem is I can't get the alias to update/replace. It does, however, seem to create one in the folder that the original alias points to. Can anyone help? Here's where my script is currently (a bit of a mess as i've been messing with it for a while):

    function alias {
    	readlink -n ~/Desktop/_AUDIO_FILES_DAILY_
    target=/Volumes/MEDIA/Audio\ Files/$(date +%y%m%d)
    if [ "$audiolink" != "$target" ]
    		mkdir /Volumes/MEDIA/Audio\ Files/$(date +%Y%m%d)
    		ln -sf /Volumes/MEDIA/Audio\ Files/$(date +%Y%m%d) ~/Desktop/_AUDIO_FILES_DAILY_
    		echo All Good
  2. iSee macrumors 68040


    Oct 25, 2004
    Look up the n option for ln. I think you want that.

    I think the problem is that it is treating ~/Desktop/_AUDIO_FILES_DAILY_ as the destination directory for creating a new link.
  3. angelwatt Moderator emeritus


    Aug 16, 2005
    You might need / at the end of the ln command,

    ln -sf /Volumes/MEDIA/Audio\ Files/$(date +%Y%m%d) ~/Desktop/_AUDIO_FILES_DAILY_/

    Maybe ... didn't try it personally
  4. zimv20 macrumors 601


    Jul 18, 2002
    what's wrong w/ deleting your link before re-setting it?
  5. Poeben thread starter macrumors 6502

    Jul 29, 2004
    Thanks for the replies. I think I may have misunderstood the difference between source and target. I did try the -n flag, but I was getting an error but that could have been a result of the swapped source/target.

    There's really no reason why I couldn't delete the link other than the hope that if I were to update it instead perhaps it would remain in the same place on the desktop.

    I'll have to wait until monday to try it out, but thanks for the help.

Share This Page