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>
Related
I have a Cocoa app for which I have created an Exported UTI and some Imported UTIs, with corresponding Document Types in the Info.plist file. All files can be opened in my app from Finder as expected.
Despite specifying an icon for all the file types however, only the file type corresponding to my exported UTI has the icon shown in Finder. All the imported UTIs have their icons unchanged, even if my app is the default for that file type.
Some other files in the file system do have icons that represent an associated application, sometimes that is the default application for that file type, sometimes it isn't.
Under what circumstances are the icons for the imported UTIs shown?
Here are the relevant parts of the Info.plist file.
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>public.mp3</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>mp3</string>
</array>
</dict>
<key>UTTypeIconFile</key>
<string>Assets.xcassets/AppIcon</string>
<key>UTTypeDescription</key>
<string>Mp3</string>
</dict>
</array>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array/>
<key>CFBundleTypeName</key>
<string>Mp3</string>
<key>CFBundleTypeIconFile</key>
<string>Assets.xcassets/AppIcon</string>
<key>LSItemContentTypes</key>
<array>
<string>public.mp3</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
I have an app which deals with two kind of file extensions, say .abc and .xyz. I want to display separate icons for these two separate extensions in Finder. How to do it?
Also, I want only .abc file type to get opened up on double click. For the .xyzfile type, I just want to display its icon in the finder.
A sample Info.plist would really help if possible.
The first part is relatively easy, though not exactly obvious. For the second one, it looks like it depends on whether you want to be able to drop .xyz files onto the app icon. If not, you'd change the CFBundleTypeRole to None, but if you do, it looks like you'd need to set LSHandlerRank to None instead (that still goes in the CFBundleDocumentTypes array).
Sample plist snippet for .abc files, with some placeholder values:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>abc</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>your-icon</string>
<key>CFBundleTypeName</key>
<string>Your File Type Description</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>your.uti.abc</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeDescription</key>
<string>Your File Type Description</string>
<key>UTTypeIconFile</key>
<string>your-icon</string>
<key>UTTypeIdentifier</key>
<string>your.uti.abc</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>abc</string>
</array>
</dict>
</dict>
</array>
Naturally, to add .xyz to that, you'd just add another <dict> to both arrays.
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>
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
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 !