将项添加到Finder / Save对话框侧栏

时间:2009-10-08 21:18:30

标签: cocoa macos applescript sidebar finder

我正在编写一个脚本,用户在操作系统上登录访客帐户,并提示他们输入网络凭据以便安装他们的网络主文件夹(当他们从本地用户文件夹中工作时受益)。

当用户注销时删除了访客文件夹,我想阻止他们在那里保存任何内容。我想将Finder和打开/保存侧边栏列表中的项目(例如“桌面”,用户名,“文档”等)替换为可以保存到其网络主文件夹中的项目。

可以使用AppleScript或Cocoa API执行此操作,还是需要修改plist并重新启动Finder? [确认。查看〜/ Library / Preferences / com.apple.sidebars.plist,我不知道如何填充它。]

类似的问题:

AppleScript: adding mounted folder to Finder Sidebar?

  • 建议使用fstab;这段代码最有可能以用户身份运行,实际上,此时自动挂载将为时已晚。

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

  • 表示没有Cocoa API,但您可以使用仅在单个头文件中记录的碳式LSSharedFileList API。
  • 有没有人知道将项目添加到Finder侧边栏的一些示例代码?

2 个答案:

答案 0 :(得分:4)

  

可以使用AppleScript或Cocoa API执行此操作,还是需要修改plist并重新启动Finder?

没有

正如我在其他问题上所说,将项目添加到侧边栏的正确方法是使用LSSharedFileList。

答案 1 :(得分:4)

一位同事提出了这种使用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
相关问题