本文介绍了将项目添加到 Finder/Save 对话框侧边栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本,在该脚本中,用户登录到操作系统上的来宾帐户并提示输入他们的网络凭据以安装他们的网络主文件夹(同时他们受益于在本地用户文件夹上工作).

当用户退出时,guest 文件夹会被删除,我想劝阻他们不要在那里保存任何东西.我想将 Finder 和打开/保存侧边栏列表中的项目(例如桌面"、用户名、文档"等)替换为可以保存到其网络主文件夹中的项目.

可以使用 AppleScript 或 Cocoa API 来做到这一点,还是我需要修改 plist 并重新启动 Finder?[确认.查看 ~/Library/Preferences/com.apple.sidebars.plist,完全不清楚我将如何填充它.]

类似问题:

AppleScript:将安装的文件夹添加到 Finder 侧边栏?>

  • 建议使用 fstab;此代码很可能会以用户身份运行,实际上,此时自动挂载为时已晚.

如何鉴于您必须为文件夹使用自定义图标,您是否以编程方式将文件夹图标放在 Finder 侧边栏上?

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

解决方案

一个同事想出了这个使用applescript的方法:

告诉应用程序Finder"启用-- 在 Finder 的侧边栏中选择您想要的路径选择文件夹库"的文件夹首选项"(主文件夹的路径)告诉应用程序系统事件"-- Command-T 将文档文件夹添加到侧边栏使用向下命令击键t"结束告诉结束告诉

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?

解决方案

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

这篇关于将项目添加到 Finder/Save 对话框侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 21:09