Issues with Applescript writing a file to Mac Hd

Hi All,

I’m an IT advisor for a British University and I am currently creating a program to help students connect to the internet in their halls of Residence. I have made a Windows version of the tool and now I have been tasked with making the OSX equivilent…

Everything is starting to come together with one exception. I have the below applescript which asks the user to input some data (their AD IT account username and their Location) and then saves their input to the Mac HD root. This works well when ran from an Admin account but fails when using a normal user account. (I’m guessing because they do not have permission to write direct to the HD root without some sort of authentication).

Does anyone know how I would make the script ask for the relevant permission so that upon entering their admin account credentials it would write to the drive ( a bit like with with administrator privileges shell cmd) ? Do you know where I would add this to the below script?

Or, could I output this file to the users’ desktop (which I assume they could write to) If so, do you know the path for this? It would need to be a generic “users” desktop as each person running the program would obviously be on different Macs with different user accounts. I know in Windows you can specify the “current user”, can this be done for Mac?

Appologies if this is a bit basic, i’ve only been using a Mac for two weeks and in some respects am trying to run before I can walk!! Applescript below:

set theText to text returned of (display dialog “Please enter your IT User Name and Building Location:” default answer “”)
set theFilePath to “results.txt” as string
set theFileReference to open for access theFilePath with write permission
write theText to theFileReference
close access theFileReference

Thanks,

-Max

Browser: Internet Explorer 8.0
Operating System: Mac OS X (10.6)

“path to desktop as text” will give you the path to the current user’s desktop.