PDA

View Full Version : AppleScript Help




aitikin
Mar 21, 2007, 12:05 PM
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
Mar 21, 2007, 02:33 PM
You can run terminal commands with AppleScript.
sudo su 'user'
do shell script ("cd ~/Music/ && rm -R iTunes && ln -s /iTunes/ iTunes
exit
exit")

aitikin
Mar 21, 2007, 07:29 PM
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:

--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
Mar 21, 2007, 07:34 PM
I am not familiar with Terminal commands.
What does:
su 'individual'; cd ~/Music/; rm -R iTunes; ln -s /iTunes/ iTunes;
actually do?

aitikin
Mar 22, 2007, 02:26 AM
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
Mar 22, 2007, 08:54 AM
Does this work?
--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

aitikin
Mar 22, 2007, 01:55 PM
I'm not at my mac, so I'll test it when I am, but I decided to work with a different solution. It's outlined here:

http://www.macosxhints.com/article.php?story=20011010033851924