Where does MacOS store the *list* of active keychains? - osx-mavericks

My login.keychain does not appear in the keychain search list. I am convinced this is a permissions problem, left over from a recent migration from an older machine, which caused havoc for a time.
I can add the keychain in Keychain Access (KA) and can use it, even adding and deleting items. However, when I quit and re-start KA, it's missing again. I tried using Terminal to add it using "security", but this had the same result. The list simply won't change.
The chain itself seems fine, and I used the Recreate and Keychain First Aid to no avail - I think because they're attacking different issues.
So, does anyone know where this information is stored, and what files I might need to fix/delete to get everything working again?

Keychain search lists are stored in /Library/Preferences/com.apple.security.plist for the system, and ~/Library/Preferences/com.apple.security.plist for each user.
The plist contents look like this:
<dict>
<key>DLDBSearchList</key>
<array>
<dict>
<key>DbName</key>
<string>... path to keychain file ...</string>
<key>GUID</key>
<string>{...}</string>
<key>SubserviceType</key>
<integer>6</integer>
</dict>
... more dict entries ...
</array>
<key>DefaultKeychain</key>
<array>
<dict>
<key>DbName</key>
<string>... path to keychain file ...</string>
<key>GUID</key>
<string>{...}</string>
<key>SubserviceType</key>
<integer>6</integer>
</dict>
</array>
</dict>

Related

How to create snippet subfolders in textmate bundle

I've just discovered textmate and I love it. I would love to use it as a way of storing my own snippets. I know how to do this in textmate but as I want to add loads of snippets I don't want them to become disorganised. I would like to add them into organised subfolders under the relevant bundle. eg under the shell script bundle I would like to add a folder that keeps all my networking snippets together. I cant find anywhere how to do this but I know it can be done as some bundles are organised like this.....Help
I managed to figure this out with a lot of trial and error and starting with this Superuser answer.
The only way to do it in TextMate 2.0 is to manually edit the info.plist file for your bundle. I suggest doing this on an exported copy of the bundle and reloading it into textmate. To export a bundle right click on the bundle in bundle editor and click Export Bundle....
Start by adding a mainMenu section at the top level of the plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
<key>mainMenu</key>
<dict>
</dict>
</dict>
</plist>
From what I can tell, the mainMenu dict supports 3 keys: excludedItems, items, and submenus. The excludedItems and items are arrays containing a list of UUIDs of either bundle items (snippets, commands, etc.) or submenus. You can get the UUID of a command or snippet by opening it in textmate and finding the uuid key; it'll look like:
<key>uuid</key>
<string>0A2DB1AC-3049-4BD5-8931-641E716990F9</string>
Once you have the UUIDs of your items you can list them in items to populate the bundle menu in the order you wish, e.g.:
<key>items</key>
<array>
<string>409b0e74-9ab5-4d35-b957-9ddf23a71c0c</string>
<string>------------------------------------</string>
<string>d2c991dc-a00e-4247-8479-f2d29f387319</string>
</array>
If you use a series of - characters in lieu of a UUID, it will create a separator in the menu. Likewise, if there are snippets you don't want to display in the bundle's menu you can add them to excludedItems.
To create submenus you have to define them inside submenus, like so:
<key>submenus</key>
<dict>
<key>71BE58B2-E486-4B21-93F1-C208D4914099</key>
<dict>
<key>items</key>
<array>
<string>6D0B2B9D-62C7-4842-BA28-F3379E887D93</string>
<string>CADC55BD-0D0A-48C8-B296-35FA7AAE09CA</string>
</array>
<key>name</key>
<string>C++ Snippets</string>
</dict>
</dict>
Each submenu needs to have an associated UUID inside <key>...</key>. I created one from an online UUID generator. You can then add the submenu's UUID to the top-level items array to add the submenu to your bundle's menu.
Finally, when loading your bundle into textmate you must first delete all cached instances of the bundle from:
~/Library/Application Support/Avian/Bundles
~/Library/Application Support/Avian/Pristine Copy/Bundles
If you don't, textmate will sometimes ignore the newly loaded bundle. Not sure if there's a cleaner way to reload a bundle, but deleting it worked for me.
For a complete example see this commit in the ROS bundle on my Github.
Just some extra info on the excellent answer above
As of TM2 rc23, you can access the UUID of an existing item by right-clicking on it in the bundle editor window (accessed with cntrl-option-command-B)
You can create a UUID in terminal.app with the command uuidgen (you could also make this into a command if you use this often)
TM2 doesn't need the cache clearing - it watches for changes in the plist.
#user96157 is clear about this, but note you have to also add your new submenu to the mainMenu. So:
<key>mainMenu</key>
<dict>
<key>items</key>
<array>
<string>COPY-UUID-FOR-YOUR-NEW-SUB-MENU-HERE!</string>

Get highlighted text

I'm developing an application in which I need to get the current highlighted text of the user outside my application, is there any way to do this?
I've read that I can register as a service but I don't want to do that.
I'm developing an application in which I need to get the current highlighted text of the user outside my application, is there any way to do this?
I've read that I can register as a service but I don't want to do that.
You really should. It's the right way.
I don't want to force the user to do a copy, I only want him to highlight the text.
(Or her.)
That's how a service works: select something (usually text), then invoke a service.
… I wan't to be able to get the highlighted text with the press of a shortcut.
You can do that, too.
Your service dictionary should look something like this:
<!--in Info.plist-->
<key>NSServices</key>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>ROT-13</string>
</dict>
<key>NSKeyEquivalent</key>
<dict>
<key>default</key>
<!-- ⌘ is implicit, and an uppercase letter likewise implies shift -->
<!-- Thus, this is ⌘-shift-e -->
<string>E</string>
</dict>
<key>NSRequiredContext</key>
<dict>
<key>NSServiceCategory</key>
<string>public.text</string>
</dict>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
⋮
</dict>

Access sidecar files in a Mac sandboxed app

I need to access sidecar XMP files in a document-based photo editor application.
The image files are the documents, and I need to access the sidecar XMP file when the user open and save an image document.
Is it possible to access sidecar files (such as XMP) in a sandboxed document-based application?
I understand that it's not possible by default, but what is the minimal temporary security exception that is needed to allow that?
Is there a workaround for this without using temporary exception?
Note that it's impossible to guarantee the the image files document-scoped bookmarks to the side-cars (as they might created by other apps on different platforms), so this solution won't work.
While this question is old I thought I would share my solution. You can add an entry to your CFBundleDocumentTypes section in your apps info.plist with the NSIsRelatedItemType set to true. Then your sandboxed app will be able to open any file the user gives permission to with the same name but has the extensions that you list. Here is an example for an xmp sidecar file:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>xmp</string>
</array>
<key>CFBundleTypeName</key>
<string>XMP sidecar</string>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>NSIsRelatedItemType</key>
<true/>
</dict>
</array>

How to keep list of files or folders on Mac sandboxed app?

I wonder is it possible to keep list of files or folders opened before on sandboxed app without re-opening them or copying to it's own library ?
Thanks in advance
To keep track of files being accessed by the user, you should create security bookmarks for each file, then that will allow your application to access these files on future runs of the application without getting permission everytime.
I've made this class that wraps up persisting permissions you already have from a using opening a file via NSOpenPanel, and then you can use the class to access that file in the future.
https://github.com/leighmcculloch/AppSandboxFileAccess
At this time only using temporary entitlements.
You should use something like
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.temporary-exception.files.absolute-path.read-write</key>
<array>
<string>absolute path to use</string>
</array>
</dict>
</plist>
I hope Apple will clarify how this can be done without 'temporary' solutions because it breaks many many apps

Be notified when a file is dropped into a folder Mac OS X

I want to write a little script on my Mac. This script will basically look for new files in a particular folder, and move them to another location when some are found.
So I was about to write something very basic, with an infinite loop, and I was wondering if something a bit more nice already exist ? Like a Listener or something I could use ?
Thanks !
You want to look into Folder Actions
http://www.simplehelp.net/2007/01/30/folder-actions-for-os-x-explained-with-real-world-examples/
An alternative way, slightly more low-level than folder actions, but I suspect more flexible, is to use launchd to watch a folder.
See launchd.plist(5), or the overview documentation for launchd (unfortunately, this overview documentation is primarily concerned with daemons, but the principle is the same; the key you're interested in is WatchPaths, so searching for that might find something more like a tutorial).
If you go this route, you need to create a .plist like the following, which runs the command /path/to/virus/scanner.sh /Junk/Downloads whenever the /Junk/Downloads directory is modified.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>localhost.clamav.clamscan</string>
<key>LowPriorityIO</key>
<true/>
<key>Nice</key>
<integer>1</integer>
<key>ProgramArguments</key>
<array>
<string>/path/to/virus/scanner.sh</string>
<string>/Junk/Downloads</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Junk/Downloads</string>
</array>
</dict>
</plist>
Put that in $HOME/Library/LaunchAgents/foo.plist, and the command launchctl load $HOME/Library/LaunchAgents/foo.plist will start it going.
Thanks Lou.
I had a look at your link and figured out how to create my own folder action doing what I want.
Just sharing the action in case someone want to use it :
It works fine for now !

Resources