Need help with bash script - symlink problems

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

  1. Poeben macrumors 6502

    Joined:
    Jul 29, 2004
    #1
    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):

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

    iSee

    Joined:
    Oct 25, 2004
    #2
    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

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    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

    zimv20

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

    Joined:
    Jul 29, 2004
    #5
    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