Create a folder with AppleScript

Discussion in 'Mac Programming' started by Beeblebrox42, May 19, 2011.

  1. macrumors newbie

    Joined:
    Mar 16, 2008
    #1
    Hi there,

    I know very little about AppleScript but I need to make a script to create folders on a server.

    Here is what I am looking to occur:

    - Check a sharepoint for a folder named %username% (where username is a 5 digit number)
    - If the folder is there, mount it
    - If the folder isn't there, create it, call it %username%.
    - mount the newly created folder

    I would be really grateful of any help with this.
     
  2. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #2
    Why Applescript ? Sounds like a 3 minute job for bash.

    Code:
    #!/bin/bash
    
    SHARE="sharepoint"
    
    usage()
    {
            echo "Usage: $0 <username>"
            echo "Synopsis : checks $SHARE for a directory named <username>, creates it if it doesn't exist"
    
    }
    
    if [ $# -eq 1 ]; then
            USERNAME=$1
            EXISTS=`ls $SHARE | grep $USERNAME | wc -l`
            if [ $EXISTS -eq 0 ]; then
                    echo "Creating folder $USERNAME"
                    mkdir $SHARE/$USERNAME
            fi
    
            echo "Here we would mount the folder using good old Unix commands"
    else
            usage
    fi
    
    Code:
    $ sh test.sh
    Usage: test.sh <username>
    Synopsis : checks sharepoint for a directory named <username>, creates it if it doesn't exist
    $ ls sharepoint/
    12345  32415  54321  98765
    $ sh test.sh 98765
    Here we would mount the folder using good old Unix commands
    $ sh test.sh 56789
    Creating folder 56789
    Here we would mount the folder using good old Unix commands
    $
    
    License to above code : Use it and you owe me 50000$ dollars as a consulting fee. This offer does not extend any warranties or garanties that the above will not awfully break any of your production servers or clients and I am fully discharged of any damages that might result in proper or misuse of this code. :D
     
  3. thread starter macrumors newbie

    Joined:
    Mar 16, 2008
    #3
    thank you so much for your help, but I really have no clue how to impliment those items of code.

    So far I have an Applescript that checks for a folder on a mounted volume, I am just looking for the code to create a folder in the event the folder is not there, then I would like a finder window to open with that folder!

    Thanks
     

Share This Page