How to read the names of open windows within an app and close a specific window, but not the entire application in an OSX app - swift

Using a Mac menubar app that is always running I want to detect when a specific app is opened, for example Pages. Then I need to be able to read the names of all the windows that are open within the Pages app and close a specific window I am looking for.

Related

Launch macOS app from FinderSync extension

I wrote an app that implements FinderSync extension.
Everything works fine, I can "communicate" by sending notifications through DistributedNotificationCenter from extension to main app. But obviously it works if the main app is running only.
Is there any mechanism to open terminated app and pass parameters?
UPDATE:
The idea is to implement simple image processing app. I want to run the main app (containing execution code and GUI) from Finder-Sync extension.
To be more specific I implemented func menu(for menu: FIMenuKind) -> NSMenu? of FIFinderSyncProtocol and I want to run/open main app when user right-clicks the menu item and selects operation I added into menu.
As I guess that my comment is at least somewhat valid, I'll put it in the answer.
Extensions allow launching of the main app by using the URL that app handles.
Communication with URL may not be enough, but you can have the app group where extension could write the data to disk and be readable by the main app or use your current way of communication with some adaptations to this method.
You can use SMLoginItemSetEnabled to launch background "helper" application.
https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled
This helper app can be launched in the background by a sandboxed app with few restrictions, and kept open when then main app closes. Your FinderSync extension can continue to communicate with the helper app even if the main app is closed.

Automatically restore last saved document on application launch

I have a Core Data Document Based application written in swift and using storyboards. Whenever I build and launch the app, instead of automatically opening the last opened document(s), it will create a new document. What I want to be able to do is have the application automatically restore whatever documents were last opened on application launch, if they are available. How can I do this?
The answer to this question does not involve a coding problem. The default application created by Xcode automatically supports the Resume functionality. What was blocking this from working was the System Preference:
General -> Close windows when quitting an app
This preference was selected and closed the windows of the app upon quitting which naturally means there is nothing to resume when the app relaunches.
OS X has a feature called Resume. It does basically what you want. This way you allow your user to decide wether to open new documents or open existing ones on launch.
You can find a starting point here. Use the Find command to locate the Resume part. I found an example here.

IOS file association - default app to open certain file

Is there any way to make my application default to open certain file types(e.g from Mail app). In this moment it is opened by Preview by default and the application is listed in the Open in.... Howeever, preview has nothing to do with this file type and this application is the only one, that can handle this file type.
So I would like to make my application default for this file type, so Preview will not open it by default. Some google search has revealed that in Mac OSX there is key like LSIsAppleDefaultForType, that can make app default, but I can't find any option for IOS...
You have to associate you app with the file types you want it to open.
You do this by adding some parameters to your Info.plist.
This post explains it:
How do I associate file types with an iPhone application?

iPhone "Share" button

Is there anything like the Android's "Share" button in iPhone?
I am just starting out in iOS development and do not have an iPhone (yet). The idea is to be able to select documents or images saved on the phone and use them in my app. I realize there is an ImagePickerController but that is not what I am looking for. I am also not looking for a third party component, rather something integrated into the OS similar to Android.
Short answer: No.
You can register your app to handle certain file types, and files of those types can then be opened by your app via UIActionSheets that may appear, for example, when you tap and hold on a file in an email. You can also transfer files to your app via iTunes. There's no 'file explorer' type feature in iOS where you can pull up a view of files saved to your phone.
For images, as you mentioned already, you must use UIImagePickerController.
From documentation
Sharing Files with the User
Applications that want to make user data files accessible can do so using application file sharing. File sharing enables the application to expose the contents of its /Documents directory to the user through iTunes. The user can then move files back and forth between the device and a desktop computer. This feature does not allow your application to share files with other applications on the same device, though. To share data and files between applications, you must the pasteboard or a document interaction controller object.
You can read more here:
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StandardBehaviors/StandardBehaviors.html%23//apple_ref/doc/uid/TP40007072-CH4-SW7

Sharing files between iPhones and PC

Im looking to see how I can share / export content from my app to allow the content to be imported in the app running on another device.
Something like if you get emailed a pdf file or word file it opens in the correct app when tapped.
I tried using the iTunes sharing approach but that allowed full access to the apps documents folder which allowed the user to mess around with content they should not be allowed to!
The content in the app will be a bundled group of images, text and audio so could be large in size so was thinking of how to transfer easily from within the app to a PC of some file sharing service that would allow the target user to then select this content from within there app and have it imported available to use.
Is this a big ask?
The 1Password app uses DropBox and it seems to work quiet well.