6

Finder サイドバーに新しい項目を追加したいと考えています。Finder が「場所」のリストを `~/Library/Preferences/com.apple.sidebarlists.plist に保持していることがわかりました。Carbon API を使用してファイルを読み取ることができ、各アイテムに名前、アイコン、およびエイリアスがあることがわかりました。

PlistEdit Pro などのサードパーティ アプリケーションを使用して、エイリアスを更新できました。私の質問は、Carbon API を使用してエイリアスを更新する方法です。Finder で開くエイリアスを作成する方法が見つかりませんでした。Dropbox と PlistEditor Pro の両方が道を見つけることができたようです。

4

3 に答える 3

6

Take a look here:

The Shared File List API is new to Launch Services in Mac OS X Leopard. This API provides access to several kinds of system-global and per-user persistent lists of file system objects, such as recent documents and applications, favorites, and login items. For details, see the new interface file LSSharedFileList.h.

You want to look for the key kLSSharedFileListFavoriteItems, which handles the items under "Places" in the Sidebar. I guess you could try to do something similar to this, using LSSharedFileListCreate to create kLSSharedFileListFavoriteItems.

Or you could use the applescript posted here, which would be way easier, but not the "Right Way"©

于 2011-01-31T16:43:29.527 に答える
3

2015 年の更新

LSSharedFileListヘッダーには、これが CoreServices フレームワークに移動したことが示さています。実際、(Xcode で) Cmd-Shift-O を押して LSSharedFileList と入力し、唯一の結果に移動すると、ジャンプ バーにヘッダーが実際に含まれていることがわかりますCoreServices.framework。いずれにせよ、キーはまだkLSSharedFileListFavoriteItemsです。

例:

+ (BOOL)appendFavoriteItemWithURL:(NSURL *)url {

  // Pessimism ...
  BOOL result = NO;

  // Do we have a file URL?
  if (url.isFileURL) {

    // Ask CoreServices for the favorite items list 
    // (kLSSharedFileListFavoriteItems)
    LSSharedFileListRef list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
    if (list) {

      // We've got the list, so try to append our item
      // (use kLSSharedFileListItemBeforeFirst vs. 
      // kLSSharedFileListItemLast if desired)
      LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(list,
                                     kLSSharedFileListItemLast,
                                     NULL,
                                     NULL,
                                     (__bridge CFURLRef)url,
                                     NULL,
                                     NULL);

      // Did it work?
      if (item) {

        // Release the item and flag success
        CFRelease(item);
        result = YES;

      }

      // Release the list
      CFRelease(list);

    }

  }

  return result;
}

使用法:

// Create the path to the favorite item to add
NSString * itemPath = [@"~/Music" stringByExpandingTildeInPath];
NSURL * itemURL = [NSURL fileURLWithPath:itemPath];

// Insert the item
[WhateverClassTheAboveFunctionIsIn appendFavoriteItemWithURL:itemURL];
于 2015-06-23T15:37:30.923 に答える
0

@Asmus : デフォルトでは、「command + T」は、フォルダーをファインダーのサイドバーに追加するためのショートカットです。u が指す Applescript は、キーボード ショートカット キー 'command + T' が手動で他のタスクに割り当てられている場合に正常に動作します。

osx lion(10.7) で他のデスクトップを表示するためのショートカット キーとして「command + T」を設定した後に実行すると、applescript が失敗します。

于 2012-05-24T11:13:06.337 に答える