The short story is that I hope to add an user specific Active Directory managed folder (My Documents) to the Finder sidebar the first time an individual logs into Mac OS 10.3 or 10.4.
With your help I have put together a script that will locate and find an individual’s Windows folder and open it in a Finder window. This script runs at login for all users.
The next step is that I would like for the script to add an alias to this location to the sidebar of the Finder. This seems to involve editing the (binary or Hex?) in the com.apple.sidebarlists.plist. Is this possible with applescript?
After that I would like to have the script check the .plist to see if this value has been added and if so then cancel the script so it won’t run over and over for every user at each login.
I’m essentially looking for some advice here. I haven’t found any applescript info about adding an alias to the Finder sidebar.
is it possible? Is there an easier way than editing the .plist file directly?
Attacking the code in com.apple.sidebars.plist seems pretty ugly. I haven’t try this, but have you created a new user, grabbed the unadorned .plist, then added the item you want there, and grabbed the .plist again to see what changed?
Would it be acceptable for you to use something like this?
tell application "Finder"
activate
reveal (choose folder)
end tell
tell application "System Events"
launch
keystroke "t" using command down
end tell
tell application "Finder" to close front Finder window
Just replace “choose folder” with your information.
Agreed. I thought there would be a similar way to reproduce a “drag and drop” process with applescript. I can’t find one. Is this what you mean by GUI scripting?
My script uses System Events to press command+T, which is the default keyboard shortcut for the “Add to Sidebar” menu item.
mistakenly referred to this as GUI scripting; Key pressing does not require GUI scripting to be turned on. I have removed that term in my original post.
Mr Phillips, thanks for all your help.
Scripting the command+T was just the sort of thing that I knew must be available in the OS and applescript.
I’ve only had Macs in my classroom for a couple of weeks and don’t know my way around them yet.
When I share this with other teachers using Mac in our Windows school district you should be a certified hero.
So it works great, and I realize after re-writing using your suggestions that every line belongs to you.
tell application "Finder"
activate
display dialog "Please enter the year you graduate:" default answer "" with icon 1
set UserInput to the text returned of result
display dialog "Please enter your username:" default answer "" with icon 1
set UserInput2 to the text returned of result
reveal ("STUDENTHOME:" & UserInput & ":" & UserInput2 & ":")
end tell
tell application "System Events"
launch
keystroke "t" using command down
end tell
tell application "Finder" to close front Finder window
At the risk of revealing myself as compleatly helpless - any tips on how to check and see if the folder is already present in the sidebar and if so cancel the script from running? I see this as a basic if / then situation but the only thing I can think of checking is to verify the presence of the sidebar alias is the .plist file. Is there an easier way?