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

$hrap

macrumors newbie
Original poster
May 7, 2013
11
0
Hi all,

New to the forum - so I apologies if this query is in the wrong place.

I work in a secondary school and we have an AD/OD environment. Users authenticate via their AD username/password and OD is used to define any policies via workgroup manager on our XServe running Lion Server.

We have 25 iMac clients all running Lion - all I'm trying to do is place an alias on the desktop when a pupil logs in which directs them to an SMB share on a Windows 2008 server (<server>\shared docs\garageband>)

The SMB share is called "garageband" and it allows pupils to drag their garageband work into it for teachers to see and review - pupils can read/write to this share.

Now, so far I've created the following shell script, called garageband.sh, changed it to executable (chmod +x garageband.sh) and placed it in /Library/Scripts:

Code:
#!/bin/bash
osascript -e 'tell application "Finder"' -e 'make new alias to folder (posix file "/Volumes/GarageBand") at desktop' -e 'end tell'

This works, providing the smb /volumes/garageband is mapped when authenticated users first logon (this is done via workgroup manager).

I've then followed various tutorials on how to make loginhooks work on the client: http://krypted.com/mac-os-x/login-logout-hooks/

However, when I log into the client - nothing happens. It does not create an alias on the desktop.

I've also tried adding the garageband.sh script to Workgroup Manager - computer group - preferences - login scripts - garageband.sh scripts. However the clients ignore it.

I'm no pro when it comes to scripting, and what makes it worse is that I didn't setup the OSX server or environment in the first place.

Any suggestions would be helpful. Thanks guys.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Hi all,

New to the forum - so I apologies if this query is in the wrong place.

I work in a secondary school and we have an AD/OD environment. Users authenticate via their AD username/password and OD is used to define any policies via workgroup manager on our XServe running Lion Server.

We have 25 iMac clients all running Lion - all I'm trying to do is place an alias on the desktop when a pupil logs in which directs them to an SMB share on a Windows 2008 server (<server>\shared docs\garageband>)

The SMB share is called "garageband" and it allows pupils to drag their garageband work into it for teachers to see and review - pupils can read/write to this share.

Now, so far I've created the following shell script, called garageband.sh, changed it to executable (chmod +x garageband.sh) and placed it in /Library/Scripts:

Code:
#!/bin/bash
osascript -e 'tell application "Finder"' -e 'make new alias to folder (posix file "/Volumes/GarageBand") at desktop' -e 'end tell'

This works, providing the smb /volumes/garageband is mapped when authenticated users first logon (this is done via workgroup manager).

I've then followed various tutorials on how to make loginhooks work on the client: http://krypted.com/mac-os-x/login-logout-hooks/

However, when I log into the client - nothing happens. It does not create an alias on the desktop.

I've also tried adding the garageband.sh script to Workgroup Manager - computer group - preferences - login scripts - garageband.sh scripts. However the clients ignore it.

I'm no pro when it comes to scripting, and what makes it worse is that I didn't setup the OSX server or environment in the first place.

Any suggestions would be helpful. Thanks guys.

I'm guessing that the script is executed immediately but before the smb /volumes/garageband is mapped. I've helped another forum member with a Logout hook in another thread here. Maybe there's some useful info for you there. Some things you can try :

Code:
#!/bin/bash
[COLOR="Red"]/usr/bin/[/COLOR]osascript -e 'tell application "Finder"' -e 'make new alias to folder (posix file "/Volumes/GarageBand") at desktop' -e 'end tell'

Make a new script and check if the volume GarageBand is mounted when you log into the client :

Code:
#!/bin/bash

su - $1 -c "/sbin/mount > ~/Desktop/mount.log"

Login and logout scripts are a deprecated technology. In most cases, you should use launchd jobs instead. See Login and Logout Scripts and how-to-run-a-script-at-login-logout-in-os-x
 

$hrap

macrumors newbie
Original poster
May 7, 2013
11
0
Kryten, thanks for your help. I've made some progress.

I used a programme called Lingon to create a launchagent (com.myscript.garageband.plist) which is placed in /library/launchagents and calls garageband.sh (that you gave me) found in /usr/sbin:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.myscript.garageband</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/sbin/garageband.sh</string>
	</array>
	<key>RunAtLoad</key>
	<false/>
	<key>StartOnMount</key>
	<true/>
</dict>
</plist>

garageband.sh:

Code:
!/bin/bash
/usr/bin/osascript -e 'tell application "Finder"' -e 'make new alias to folder (posix file "/Volumes/GarageBand") at desktop' -e 'end tell'

This works - a pupil logs on, and there is the garageband alias on the desktop.

I've also made a logouthook script that deletes the garageband alias from the desktop - this works too.

Now, the problem. The above worked on my iMac, but when I tried it on a macbook pro (running Lion) - it didn't work. I did the following:

copied the above plist file to \library\launchagents
copied the garageband.sh script to \usr\sbin

When I log onto the macbook pro as a pupil - it fails to create the alias.

Do you know what i'm missing? Do I have to run any sudo commands, or do you think that I may need to have Lingon installed on every client that runs the launch agent perhaps?

Regards,
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Do you know what i'm missing? Do I have to run any sudo commands, or do you think that I may need to have Lingon installed on every client that runs the launch agent perhaps?

Regards,

You definitely do NOT need to have Lingon installed on every client. Lingon just creates the launchd plist files and has nothing to do with it working or not. I'm thinking it 's an ownership problem. Things to check on the macbook pro (running Lion) :

Check if your com.myscript.garageband.plist launchagent is loaded. Open Terminal application and type the following line and press enter :

Code:
launchctl list | grep myscript

Example :

Code:
Aldebaran:~ test$ launchctl list | grep down
-	0	com.test.downloadsmove

If your com.myscript.garageband.plist launchagent is loaded it should produce some output. If no output is returned it's not loaded.

Load it manually. Type the folowing line in Terminal and press enter:

Code:
launchctl load /path/to/your/com.myscript.garageband.plist

If there's an ownership problem launchctl will complain about it.

Example :

Code:
Aldebaran:~ test$ launchctl load Library/LaunchAgents/com.test.downloadsmove.plist 
launchctl: Dubious ownership on file (skipping): Library/LaunchAgents/com.test.downloadsmove.plist
nothing found to load


Note : Unix is case sensitive!
/library/launchagents is not the same as /Library/LaunchAgents
\library\launchagents and \usr\sbin --> forward slashes please!
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,424
A sea of green
IIRC, launchd plists residing in /Library/LaunchAgents must be owned by root, and have read-only permissions for group and other (i.e. all except owner).

If these conditions aren't met, then launchd silently ignores the plist.

This is done for security reasons.
 

$hrap

macrumors newbie
Original poster
May 7, 2013
11
0
Code:
Aldebaran:~ test$ launchctl load Library/LaunchAgents/com.test.downloadsmove.plist 
launchctl: Dubious ownership on file (skipping): Library/LaunchAgents/com.test.downloadsmove.plist
nothing found to load

Kryten - you're right, this is the message I got when I ran launchctl load manually.

Sorry for late response. We have a network meltdown last week so I had to sideline the launch agent problem. How do I get round the dubious file permission problem? Do I run the chmod 755 command?

The other problem I've encountered is that when the same pupil logs in multiple times - it recreates the garageband alias - the pupil ends up with multiple copies of the alias on the desktop.

Regards.
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Kryten - you're right, this is the message I got when I ran launchctl load manually.

Sorry for late response. We have a network meltdown last week so I had to sideline the launch agent problem. How do I get round the dubious file permission problem? Do I run the chmod 755 command?

The other problem I've encountered is that when the same pupil logs in multiple times - it recreates the garageband alias - the pupil ends up with multiple copies of the alias on the desktop.

Regards.

In Terminal :

Code:
sudo chown 0:0 /path/to/your/com.myscript.garageband.plist
sudo chmod 644 /path/to/your/com.myscript.garageband.plist

Multiple alias problem. Try this :

Code:
tell application "Finder"
	set fileExists to exists file "GarageBand" of desktop
	if not fileExists then make new alias to folder (POSIX file "/Volumes/GarageBand") at desktop
end tell
 

$hrap

macrumors newbie
Original poster
May 7, 2013
11
0
In Terminal :

Code:
sudo chown 0:0 /path/to/your/com.myscript.garageband.plist
sudo chmod 644 /path/to/your/com.myscript.garageband.plist
[/CODE]

Kryten,

I've managed to sort the duplicate aliases. I just added the following to a predefined logout.sh script I found buried in Library/Scripts:

Code:
rm ~/Desktop/GarageBand

However, the chown commands didn't work, I've tried:

Code:
sudo chown 0:0 /library/lauchagents/com.myscript.garageband.plist
sudo chmod 644 /library/lauchagents/com.myscript.garageband.plist

Still no luck when a pupil logs on.

Further info - I have the following:

garageband.sh - located in /Library/Scripts/Myscripts
com.myscript.garageband.plist - located in /Library/Launchagents - this called the garageband.sh script

Do I have to perform the chown command on the garageband.sh script, too?
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Kryten,

I've managed to sort the duplicate aliases. I just added the following to a predefined logout.sh script I found buried in Library/Scripts:

Code:
rm ~/Desktop/GarageBand

However, the chown commands didn't work, I've tried:

Code:
sudo chown 0:0 /library/lauchagents/com.myscript.garageband.plist
sudo chmod 644 /library/lauchagents/com.myscript.garageband.plist

Still no luck when a pupil logs on.

Further info - I have the following:

garageband.sh - located in /Library/Scripts/Myscripts
com.myscript.garageband.plist - located in /Library/Launchagents - this called the garageband.sh script

Do I have to perform the chown command on the garageband.sh script, too?

It confuses me a bit that you keep mixing lowercase and uppercase examples to paths in your replies. Please post the output of the following commands in Terminal. Post it as a screenshot of your Terminal window so it's clear exactly what you typed in and what output is returned from the commands.

Log on as pupil on that Lion machine :

Code:
whoami
ls -al /Library/Scripts/Myscripts/garageband.sh
ls -al /Library/LaunchAgents/com.myscript.garageband.plist
sudo chown -v 0:0 /Library/LaunchAgents/com.myscript.garageband.plist
sudo chmod -vv 644 /Library/LaunchAgents/com.myscript.garageband.plist
(may need sudo as well)launchctl list | grep myscript
# This is a comment. No need to type this. If the launchctl list shows no output load the com.myscript.garageband.plist manually
(may need sudo as well)launchctl load /Library/LaunchAgents/com.myscript.garageband.plist

As a pupil on that Lion machine :

run the garageband.sh shell script manually if execution is allowed.

Code:
/Library/Scripts/Myscripts/garageband.sh

You might also want to check some logs in the Console application.
 
Last edited:

$hrap

macrumors newbie
Original poster
May 7, 2013
11
0
It confuses me a bit that you keep mixing lowercase and uppercase examples to paths in your replies.

The lower and upper case mixture is not intentional, to be honest I've not even noticed it until you pointed it out. I apologise if it's confused you, though.

I'll run the command tomorrow when I get to work.

Cheers.
 

$hrap

macrumors newbie
Original poster
May 7, 2013
11
0
Kryten,

After a log day battling with the Garageband alias, I've finally made some progress.

The reason why the LaunchAgent wasn't running for pupils is because "system" did not have read/write access in the permissions of the .plist file in Library/LaunchAgents.

What I did was recreate the .plist using Lingon, then I copied it with it's current permissions to another mac (along with the garageband.sh script) and it worked.

However, I've facing a new problem:

When a pupil launches Garageband, and they try to save a new project to the GarageBand alias folder - it lets them into the folder but it will not allow them to save to it, OSX 10.7 complains that the user doesn't have permission to save to the folder - yet they can get to it and save correctly via the mounted smb share volume - smb:\\Shared Documents\GarageBand.

GarageBand is a folder on a Windows Server it has the correct permissions and is set to allow pupils to write to the folder.

Is there something I have to put into the garageband.sh script to set permissions for the alias to allow pupils to read/write to the shortcut?

I'm getting multiple permission errors "The operation can't be completed because you don't have permission to access some of the items" is one of them.
Thanks for your help so far.
 

$hrap

macrumors newbie
Original poster
May 7, 2013
11
0
Kryten,

Abandoned the alias script. I've decided to try a symbolic link instead.

I pointed my LaunchAgent (Library/LaunchAgents/com.MyScript.GarageBand.plist) to /Library/Scripts/MyScripts/sym-link.sh, which contains the following:

Code:
#!/bin/bash
ln -s "/Volumes/RMShared Documents/GarageBand" ~/Music/GarageBand

When I log on as a pupil, sure enough, the default Garageband folder \Users\Music\Garageband links itself to the mounted SMB share smb://<server>/SharedDocuments/Garageband, which is what I want it to do.

However, when a pupil opens up Garageband, and tries to save a new .band file directly into the redirected symbolic linked folder /Users/Music/Garageband folder it just says permission denied and file is corrupted.

From the server, pupils have read and write NTFS permissions to the SharedDocuments\Garageband folder, and weirdly when a pupil saves a .band file to their desktop (in 10.7) and drag it into the Mounted SharedDocuments\Garageband folder, it saves - it just will not save via Garageband directly into the mounted folder via the symbolic link.

Sorry if I haven't explained myself well enough. Any ideas? It's definately some sort of permission problem.

Regards
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.