Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 7, 2013, 03:59 PM   #1
$hrap
macrumors newbie
 
Join Date: May 2013
Nightmare with loginhooks

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.
$hrap is offline   0 Reply With Quote
Old May 7, 2013, 08:40 PM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Originally Posted by $hrap View Post
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
/usr/bin/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
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old May 8, 2013, 11:58 AM   #3
$hrap
Thread Starter
macrumors newbie
 
Join Date: May 2013
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,
$hrap is offline   0 Reply With Quote
Old May 8, 2013, 02:18 PM   #4
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Originally Posted by $hrap View Post
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!
__________________
Space Corps Directive 34124

Last edited by kryten2; May 8, 2013 at 02:39 PM.
kryten2 is offline   0 Reply With Quote
Old May 8, 2013, 02:41 PM   #5
chown33
macrumors 603
 
Join Date: Aug 2009
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.
chown33 is offline   0 Reply With Quote
Old May 13, 2013, 03:53 AM   #6
$hrap
Thread Starter
macrumors newbie
 
Join Date: May 2013
Quote:
Originally Posted by kryten2 View Post
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 by $hrap; May 13, 2013 at 05:18 AM.
$hrap is offline   0 Reply With Quote
Old May 13, 2013, 07:56 AM   #7
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Originally Posted by $hrap View Post
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
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old May 13, 2013, 09:55 AM   #8
$hrap
Thread Starter
macrumors newbie
 
Join Date: May 2013
Quote:
Originally Posted by kryten2 View Post
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 by $hrap; May 13, 2013 at 10:00 AM.
$hrap is offline   0 Reply With Quote
Old May 13, 2013, 11:10 AM   #9
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Originally Posted by $hrap View Post
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.
__________________
Space Corps Directive 34124

Last edited by kryten2; May 13, 2013 at 03:14 PM.
kryten2 is offline   0 Reply With Quote
Old May 13, 2013, 02:46 PM   #10
$hrap
Thread Starter
macrumors newbie
 
Join Date: May 2013
Quote:
Originally Posted by kryten2 View Post
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 is offline   0 Reply With Quote
Old May 14, 2013, 11:02 AM   #11
$hrap
Thread Starter
macrumors newbie
 
Join Date: May 2013
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 is offline   0 Reply With Quote
Old May 15, 2013, 11:47 AM   #12
$hrap
Thread Starter
macrumors newbie
 
Join Date: May 2013
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
$hrap is offline   0 Reply With Quote
Old May 15, 2013, 02:19 PM   #13
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
I'm sorry I can't help you any further with this problem, I've run out of ideas. It may not be related and even be a stupid suggestion but have you looked at this link. You can also start another thread in the dedicated Mac OS X Server, Xserve, and Networking forum section Mac OS X Server, Xserve, and Networking
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old May 16, 2013, 03:58 AM   #14
$hrap
Thread Starter
macrumors newbie
 
Join Date: May 2013
Kryten, thanks for all your help.
$hrap is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
My Craigslist Nightmare Type R Buying Tips and Advice 81 Sep 17, 2013 12:50 PM
Very nearly a Nightmare! Be Warned! heyapple MacBook Pro 8 Mar 28, 2013 02:23 PM
Filevault nightmare wozzerage Mac Basics and Help 3 Feb 28, 2013 01:03 PM
Fusion nightmare gnopx Mac mini 31 Feb 20, 2013 11:14 AM
iPad Mini: Nightmare!!! Oreon iPad 7 Dec 17, 2012 02:07 PM

Forum Jump

All times are GMT -5. The time now is 03:16 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC