【问题标题】:Add an item to the Finder/Save dialog sidebar将项目添加到 Finder/保存对话框侧边栏
【发布时间】:2010-12-05 03:54:09
【问题描述】:

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

当用户注销时,来宾文件夹会被删除,我想劝阻他们不要在那里保存任何东西。我想将 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 侧边栏的示例代码吗?

【问题讨论】:

    标签: cocoa macos applescript sidebar finder


    【解决方案1】:

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

    没有。

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

    【讨论】:

    • 是否有任何示例代码可以帮助解决这个问题?我对 Cocoa 编程知之甚少,但对 Carbon 编程一无所知。是的,我确实知道如何使用 C 和 C++ 进行编程,但是我现在想要完成的 API 中只有一个小任务,我不清楚如何进行。
    • 这不是碳;它是核心服务。您可以查看 Growl 的代码——我们访问 Login Items 列表,但过程相同。 code.google.com/p/growl 代码在 GrowlPreferencesController, IIRC 中。
    • 谢谢;我一定会看看的。
    • @PeterHosey:你能指导我如何从图像文件中获取 IconRef,以便我可以使用 LSSharedFileList 在 FinderSidebar 中使用图标。
    【解决方案2】:

    一位同事想出了这个使用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
    

    【讨论】:

    • 这很脆弱。如果 Apple 更改或删除 ⌘T 作为该菜单项的键盘命令,或者如果用户在另一个菜单项上设置了 ⌘T,则会破坏您的脚本。
    • 如果用户在你的脚本运行时尝试使用计算机,它也会中断——这很可能;他们刚刚登录并想要完成他们的工作。
    • 而且你知道... Apple 更改了 ⌘T 以在 Finder 中打开一个新选项卡。新命令现在是 ^⌘T。
    猜你喜欢
    • 2011-06-18
    • 2021-09-25
    • 2011-04-14
    • 2018-12-19
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多