AppleScript Help

Discussion in 'Mac Programming' started by aitikin, Mar 21, 2007.

  1. macrumors newbie

    Joined:
    May 24, 2006
    #1
    I'm currently trying to write an AppleScript so that my boss can use it when he sets up new accounts on our (Recording) Studio machine. We all share the same iTunes files and folders in the folder /iTunes/ (who would've thought to put that there?) and when we sent up new accounts we need to short cut (or symlink as the case would truly be) their iTunes folder to that one. I know how to do it in theory, I just have never worked with AppleScript before.

    Basically what needs to be done is (as thought this were a terminal)


    where user=the new users shortname
    sudo su 'user'
    cd ~/Music/ && rm -R iTunes && ln -s /iTunes/ iTunes
    exit
    exit

    However I don't know applescript. If I could run it without showing the terminal, it'd be nice because my boss is kinda...not as good as he thinks he is and I don't feel like having to sit down and explain what every piece does.

    Any help that anyone can give would be much appreciated.
     
  2. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #2
    You can run terminal commands with AppleScript.
    Code:
    sudo su 'user'
    do shell script ("cd ~/Music/ && rm -R iTunes && ln -s /iTunes/ iTunes
    exit
    exit")
     
  3. thread starter macrumors newbie

    Joined:
    May 24, 2006
    #3
    Ok, I've been toying with this some more and found I can to get a point. I can't figure out how exactly to imput a variable from the applescript to the shell script. Here's what I have so far:

    Code:
    --Getting user's short name
    
    set individual to display dialog "Which user's account needs to have the iTunes changed?" default answer "Put the user's SHORT NAME here."
    
    choose folder with prompt "Where is the shared iTunes folder?"
    
    do shell script "su 'individual'; cd ~/Music/; rm -R iTunes; ln -s /iTunes/ iTunes;" with administrator privileges
    Every time I run that script it basically times out. I've also tried using $individual rather than 'individual' but it made no difference.
     
  4. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #4
    I am not familiar with Terminal commands.
    What does:
    su 'individual'; cd ~/Music/; rm -R iTunes; ln -s /iTunes/ iTunes;
    actually do?
     
  5. thread starter macrumors newbie

    Joined:
    May 24, 2006
    #5
    su == switch user
    cd ~/Music/ will change it to that user's Music folder
    rm -R iTunes will remove the folder iTunes and it's contents
    ln -s /iTunes/ iTunes (most confusing part) will create a symlink (AKA alias) from /iTunes/ (Startup disc, iTunes (where we keep our iTunes stuff, evidently)) to the current folder as iTunes.

    I switch users there, rather than staying root, so that I don't have to modify owner and permissions later.
     
  6. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #6
    Does this work?
    Code:
    --Get user's short name
    set user_name to (item 4 of ((system info) as list))
    
    --Run shell script
    do shell script "su '" & user_name & "'; cd ~/Music/; rm -R iTunes; ln -s /iTunes/ iTunes;" with administrator privileges
     
  7. thread starter macrumors newbie

    Joined:
    May 24, 2006
    #7

Share This Page