Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aitikin

macrumors newbie
Original poster
May 24, 2006
8
0
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.
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
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")
 

aitikin

macrumors newbie
Original poster
May 24, 2006
8
0
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.
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
I am not familiar with Terminal commands.
What does:
su 'individual'; cd ~/Music/; rm -R iTunes; ln -s /iTunes/ iTunes;
actually do?
 

aitikin

macrumors newbie
Original poster
May 24, 2006
8
0
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.
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.