views:

386

answers:

2

I'm working on a script where a user logs into a guest account on OS and is prompted for their network credentials in order to mount their network home folder (while they benefit from working on a local user folder).

As the guest folder is deleted when users log out, I want to discourage them from saving anything there. I would like to replace the items on the Finder and Open/Save sidebar lists (such as "Desktop", username, "Documents", etc) with ones that would save into their network home folder.

It is possible to do this using AppleScript or Cocoa APIs, or do I need to modify a plist and restart the Finder? [Ack. Looking into ~/Library/Preferences/com.apple.sidebars.plist, it isn't at all clear how I'd populate it.]

Similar Questions:

AppleScript: adding mounted folder to Finder Sidebar?

  • suggests using fstab; this code will most likely run as a user and really, automounting at that point would be too late.

How do you programmatically put folder icons on the Finder sidebar, given that you have to use a custom icon for the folder?

  • Says there is no Cocoa API, but that you can use a carbon-style LSSharedFileList API that is only documented in a single header file.
  • Does anyone know of some example code to add an item to the Finder sidebar?
+1  A: 

It is possible to do this using AppleScript or Cocoa APIs, or do I need to modify a plist and restart the Finder?

No.

As I said on that other question, the correct way to add an item to the sidebar is to use LSSharedFileList.

Peter Hosey
Is there any sample code to help with that? I know a little about Cocoa programming, but nothing about Carbon programming. Yes, I do know how to program in C and C++, but there is only this one small task in the API that I want to complete right now, and I'm unclear how to proceed.
Clinton Blackmore
It's not Carbon; it's Core Services. You can look at Growl's code—we access the Login Items list, but it's the same procedure. http://code.google.com/p/growl The code is in GrowlPreferencesController, IIRC.
Peter Hosey
Thank you; I'll be sure to take a look at that.
Clinton Blackmore
A: 

A co-worker came up with this method that uses applescript:

tell application "Finder"
    activate
    -- Select the path you want on the sidebar in the Finder
    select folder "Preferences" of folder "Library" of (path to home folder)
    tell application "System Events"
     -- Command-T adds the Documents Folder to the sidebar
     keystroke "t" using command down
    end tell
end tell
Clinton Blackmore
That's fragile. If Apple changes or removes ⌘T as the key command for that menu item, or if the user has set ⌘T on another menu item, that will break your script.
Peter Hosey
It will also break if the user tries to use the computer while your script is running — which is likely; they've just logged in and want to get their stuff done.
Kevin Reid