PDA

View Full Version : Create a folder with AppleScript




Beeblebrox42
May 19, 2011, 06:08 AM
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.



KnightWRX
May 19, 2011, 06:34 AM
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.

Why Applescript ? Sounds like a 3 minute job for bash.


#!/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



$ 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

Beeblebrox42
May 19, 2011, 08:17 AM
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