Posted on 08-22-2012 11:22 AM
I’m writing a bash script to migrate the Mac users from Entourage to Outlook 2011. The Bash code is so that I can run this through Casper Remote.
However the migration commands only exist in applescript, so I am using osascript to execute them. It’s a pretty long applescript so a one line osascript –e won’t cut it. I am using
Osascript<<EndMigration
APPLESCRIPT CODE
EndMigration
Another snag: the code between the EndMigration tags has to execute as the user. By default, casper uses the super user account, so the AS code won’t execute correctly. Do you know how I would be able to execute this osascript as the user? So far I have this:
LoggedInUser=`who | grep console | awk ‘{print $1}’`
Su $LoggedInUser –c “osascript<<EndMigration
APPLESCRIPT CODE
EndMigration
“
But this changes the quoting in the osascript block and the script fails. I was wondering if you know a way around that?
Thanks to talkingmoose for the Outlook setup script, btw. Any help on this is much appreciated!
---
Oh and at the same time, how can I run jamfHelper in fs mode to prevent user input while the rest of the script runs in the background? I used the "&" notation at the end of the jamfHelper command, but the rest of the script just sits and waits anyway.
Posted on 03-27-2013 06:32 AM
Just figured this out, this is working for me:
# Discover logged in user
user=`stat -f%Su /dev/console`
sudo -u $user /usr/bin/osascript <<EndMigration
APPLESCRIPT HERE
EndMigration
However, I too had issues with various quotes in the AppleScript block. I was able to avoid the use of awk (using cut instead, I like it better for easy things) and was able to fix the script so it runs.