Copy and pasting selected text from the current, from a Mac sandboxed application - swift

I am trying, from a sandboxed menubar application, to get the selected (highlighted) text in the current application.
I was using accessibility before and traversing the main menu of the application until finding the copy item but unfortunately, I need to sandbox the application and this is no more a valid approach.
I would like to simulate the ⌘ + C keyboard shortcut but so far all my attempts failed.

so far all my attempts failed
There is a reason for that...
A core purpose of the sandbox is to provide isolation between applications, to prevent one application from accessing the data of another. So what you are asking is how to break out of the sandbox...
If you are writing accessibility software take a look at How to use Accessibility with sandboxed app? for maybe the smallest glimmer of a hope.
Otherwise your current path is a (hopefully, its a sandbox) dead-end, security has a price, sorry.

Related

How to make a background macOS application?

I'm trying to develop a macOS app that performs operations on a file when the user chooses to do so. My goal is to let a user right-click a file, select my app from the list of services so that the app will pop open a UI with things like configuration options, etc.
A prime example would be Evernote's "Add to Evernote"; when a user clicks it, the Evernote app opens and saves the file there. In addition, I need to switch control to the UI, so that the user can input some settings, before performing any file operations.
The place where I'm stuck now is how to get the app/UI open when the user clicks it from the contextual menu, as well as keeping the UI hidden initially. From some googling, I think what I need to make is an agent? I'm not really sure.
Any help would be appreciated, thanks!

OwnCloud enhance core features with App (eg. user registration)

I started looking into OwnCloud app development to add some capabilities I would like to my server. To me it seems like Apps can't modify anything like the Login page or User Management page. Is this the case?
I want to build a user registration app and would love to integrate it into the user management page (if not and it has to exist as its own app page not a big deal). The one big problem I see so far is not being able to add a "Register" link to the login page. I could just go in and add it to the source manually, but I would like to keep the App self contained so others can use it too.
If this is not possible to do in an App I may just need to modify the core application and then see if they will accept my feature addition in a pull request.
Thanks to anyone who can shed some light on this for me. I don't want to waste my time trying to figure out how to do it with an App on the platform if it wont be doable.
After a lot of digging around I did figure out a way to do this.
In the App's app.php file, you can force a script to be loaded if the plugin is enabled:
$api->addScript('script_name'); // without .js
In that script jQuery can be used to add the elements to the page where you need them.
This was a good solution for me since I only needed to add a single button to the login page. I can see this being a bad idea if you want to make vast modifications. At that point you might as well just create a separate page that you have full control over.

Is it possible to provide additional info about my app to the system search?

There's a system search in iOS that allows users to search though the whole device by searching entered keyword for app names, mail messages, calendar and etc. Is it possible to provide some additional information (content info) about my app to system search? We are developing some rich-graphic-content app and there are various objects there.
The customer asked us, is it possible to implement such use case: a user enters the name of some object and system search finds that object and shows our app name in the result list :) Maybe it's possible to create some "sitemap" with information about the app content, to put that somewhere into plist and to ask system search to use that for search index. I'm pretty sure it's impossible, just want to be 100% sure :)
UPDATE: One thought on that - maybe system search also uses app description text from itunes? If so then we could place additional information there and to workaround that :)
For static keywords (that are pre-defined when building the app), you can do this: How to get an iPhone app to appear in Spotlight with a query that doesn't exactly match
Unfortunately, there doesn't seem to be any way to add keywords dynamically, e.g. for the objects/files created with your app, like the Apple-provided apps do. Hopefully, the ability to add your app's contents to Spotlight will be added in a future version of iOS (7+).

Localization issue in iphone

I need to make an application in which the user can toggle between two languages on triggering a click event on a button.
The problem here is that I have seen examples in which, if we want to load our localized nib file, then we need to change the language from the settings options and we can get the proper nib file loaded according to language selected.
I want to do this within my application, meaning I don't want to go to the settings menu and change the language and then reload the application.
I just want the above effect within my application (that is, through a button click event the app should be able to toggle between two languages).
Is it possible, and does Apple allow it?
Nobody here can tell you whether Apple will allow it, but if your app is well designed and there's a good reason for this departure from the usual way of doing things, you've probably got a good shot.
There's nothing to prevent you from loading a nib file localized for a different region. I'd probably avoid trying to use Apple's automatic mechanism, though. Just name your nib files using some pattern and load the appropriate one.
If you want your life to easy, you will take advantage of the Localization built into the operating system. Otherwise, you will have write your own methods to load localized strings or nib files.
There is no reason for Apple to reject an app that shows localized text based on an in-app setting. I work to help developers localize apps and, although I don't suggest this approach, they have done it and I've never heard of a rejection from Apple.
What you won't be able to do is use Apple's built-in tools, which rely on the system settings to determine a user's language and push the text from a Localizable.strings file. But it honestly won't take you too long to implement a similar system yourself using functions akin to gettext.
You essentially need to implement the same basic logic as any localization system:
1) Surround your in-app texts in a function that will display the proper language based on the user's chosen settings
2) Export your source texts (probably English into file
3) Translate the English strings into each language in a separate file
The function you write can follow the lines of gettext, which has examples in many programming languages. If the settings is "French" grab the equivalent string from the French file. If the setting is English, just print the English.
You won't be able to use Apple's tools, but you CAN do it on your own and Apple won't really care as far as I know. However, if you choose to localize into an Apple-supported language, follow this app localization tutorial for iOS using the standard Localizable.strings method.

Optional group with PSToogleSwitch

I'd like to have a settings bundle behavior similar to the iPhone WiFi settings.
If you select the toggle switch and set it to on, an optional group with the specific settings appears. How is this done? I haven't found any clue by now.
If you are writing a preferences bundle yourself (jailbreak-level), you can dynamically add and remove PSSpecifiers in your switch's "set" selector. If this is for an App Store application, I do not believe that is possible (in which case, I would suggest attempting to integrate these preferences into your application, where you have code-level control over their display and setup.)