"Ask for Finder Items" in Swift - swift

I am trying to open a file-browsing window similar to the one shown in the screenshot where you can "select files and click open/select" in my Swift application when the user clicks on the "Browse" button.
In Automator, this is done by using the "Ask for Finder Items" action, and in Swift
NSWorkspace().selectFile("\(fileName)", inFileViewerRootedAtPath: "/Library")
opens up a new instance of Finder.app itself; what should I do if I would like to emulate the behavior seen in the Automator action?

You're looking for the NSOpenPanel class. It has several configurable properties for which kinds of files can be selected, and when the user finishes selecting files, you can access them via the URLs property. You can also read more about it in the File System Programming Guide.

Related

macOS applicationDockMenu remove universal items in the app's dockTile

I am developing a cocoa app for macOS and was manipulating the app's dock menu. I realize there are universal menu items such as "Options", "Show All Windows" and "Hide" in every app's dock menu.
In my case, those items/buttons do not work so I want to remove them. For example, "Options -> Keep In Dock" won't work because the executed application is a cloned one and will be deleted after quit(I know it is weird but that's what the app does).
Is there anyway that I can remove one or all of them? I think it might be impossible but a consultation won't do any harm.
Universal items I'm trying to remove
Or, can I set the callback of "Show All Windows" or "Hide" programmatically? Update: I just found applicationWillHide/DidHide to set the callback of "Hide" item. But seems like I can not abort or abort its hide process unless I set the "canHide" window I don't want hide to false.
There is no way to do this. They are inserted by the system and and you can not modify their behaviour.

How to open a folder via Finder using Swift in Xcode from a Finder Sync Extension

I am trying to open a specific folder when a user clicks on a menu item in the Finder Sync Extension I am writing. I know there are many similar questions posted because I have looked at them but none of the solutions are working in my application.
Here is the folder I am trying to open:
let folder = "/Users/username/some/folder"
This post, Show folder's contents in finder using Swift, suggested doing the following:
NSWorkspace.shared().selectFile(nil, inFileViewerRootedAtPath: folder)
When I tired this method, the menu item does nothing when it is clicked.
There are many other posts I have looked at and I have also tried the following methods but I haven't had anything work yet.
NSWorkspace.shared().activateFileViewerSelecting([URL(fileURLWithPath: safeZone, isDirectory: true)])
This results in the containing folder "some" being opened and the folder I actually wanted to open "folder" is just highlighted.
NSWorkspace.shared().openFile(safeZone)
When I tired this method, the menu item does nothing when it is clicked.
NSWorkspace.shared().open(URL(fileURLWithPath: safeZone, isDirectory: true))
When I tried this method, I got a message from Finder stating:
The application “MyAppFileSyncExtension” does not have permission to open “folder.”
Is there some way via Xcode to give the extension more permissions? I know my parent app can read and write to this folder no problem.
NSWorkspace.shared().openFile(folder, withApplication: "Finder")
When I tired this method, the menu item does nothing when it is clicked.
I am guessing that none of these methods are working because I am trying to do this from Finder Sync Extension. Does anyone know how to get around this issue?
UPDATE
I tested those methods from the parent application and most of them work. The question is how to create this type of behavior from a Finder Sync Extension. Any help would be greatly appreciated.

Inject OnClick Event into running EXE

Is it possible with some program to to send an OnClick Event eg: MenuNewClick (File New) or others.
I have an application that has no Keyboard shortcuts.
When I use a Resource Editor I can see the Delphi Forms for each OnClick Event I need.
I would just like to be able to send these OnClick Events with Keyboard Shortcuts into the running exe.
Have used apps like Darker's Enabler, EDA Preview that allow you to modify the layout of a running exe.
Possible ?
Even this forum has options "Keyboard shortcuts
Enable keyboard shortcuts (when enabled, press ? for help)"
Thanks.
If the application is indeed made with Delphi and if it uses default TMainMenu component you could modify the RCData in which the .dfm is stored (this data alows you to view the form and its properties with programs like PE Exporer and similar) in a way that you change the AutoHotkeys property of TMainMenu to maAutomatic and then change ShortCut property of each menu item to contain proper keyboard shortcut.
If you have access to Delphi I recomend you first make an example application which will have all available shourctuts implemented so you could comparison the RCData between these two applications and made necessary changes.
NOTE: What I'm suggesting will require editing the EXE resource data so make sure you are working on a copy of the exe and not on the real one so you don't break your application.

How to change open with options in navigator depending upon name of the resource?

I am working on eclipse RCP application which implements CommonNavigator view to display navigator. I have few LinkedResources in navigator that link to files on the file system with custom extension. These custom extension files are opened in custom editor as well as in TextEditor.
One of the file named default.ext will be common to all the projects and I want to keep it read only. Is it possible to open file in custom editor only? For ex. Default.ext should be opened in only custom editor, however Test.ext should be opened in custom editor as well as text editor.
This way I could handle save action in my editor depending upon file name and keep the file read only.
Is there any other way to keep files read only?
Short answer: not possible in the way you describe.
Long answer: if somebody really wants to modify a file then there's no way or need to stop this. What you can do is either (1) hide the file from user or (2) set Read-only flag to discourage users from modifying the file.

iOS simulator options changes

When I open any song site through simulator of iPhone or iPad say mp3skull.com . and when i click on option download It gives me the Alertview option to COPY and OPEN . IS there any way I can give one more option in this .say open copy download. for more clarity shown in page :
1st off: I no not think that adding a specific item there is possbile.
Now assuming you actually want to add a "Download" button, consider this:
Opening a file by default means you have to download the file first
"Download" on a PC/Mac just puts the file into a "known" folder where you can open it with any program later while "open" puts it into a (possibly) random temp folder and then runs the default program
Due to the nature of safari in iOS a "Download" button would be more like "Store in Safari for later"
Open in safari is -> Download, Store, Ask user what app he wants to use to open the file type.
So considering the above points I do not see how a "Download" button would function. If you have some more details what you want your button to do, maybe there is an alternative that will work for you.