Open default application with nativescript - nativescript

I am quite surprised I have yet to find an answer to this on the internet.
How do I open a native/default app from my nativescript app?
In this instance I want to open a map application with a location parameter (not sure if it will be a string, coordinates, etc).

You can use utils
var utilsModule = require("tns-core-modules/utils/utils");
utilsModule.openUrl("<< for example: maps short link>>");
In fact it will try to open map link with browser. But android && ios will ask to you “do you want to open it via Maps?” at first.
There may be some plugins for opening via maps directly without any question but I think this way is better (you dont need to install a plugin)
For more info about utils, see that

Related

Launcher.LaunchUriAsync does not work on Xamarin Forms UWP [duplicate]

no Error just nothing happen and file target still there in my path
public void keyboard(){
ProcessStartInfo touchkey = new ProcessStartInfo(#"C:\Program
Files\Common Files\microsoft shared\ink\TabTip.exe");
touchkey.WorkingDirectory = #"C:\";
touchkey.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(touchkey);
}
Update
The suggested solution threw a `UnauthorizedAccessException`:
var path = #"ms-appx://C:/Program Files/Common Files/microsoft
shared/ink/TabTip.exe";
var file = await
Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(path);
await Windows.System.Launcher.LaunchFileAsync(file);
Update2
I try to use FullTrustProcessLauncher it's work fine but like code before Keyboard tabtip.exe not show I dont know what should I do
await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
});
UWP applications are sandboxed and cannot launch other processes directly due to security restrictions.
The only way to launch other applications is if those applications have a URI registered, or an application is a default handler for a particular file type.
In those instances, you can use methods such as LaunchUriAsync or LaunchFileAsync
Without TabTip.exe
I recognize you are trying to show the on-screen keyboard judging by the path of the exe. I suggest a better approach would be to trigger the new touch-enabled keyboard which is easily possible without additional hassle from UWP with InputPane API:
var pane = InputPane.GetForCurrentView();
pane.TryShow();
With TabTip.exe
If you prefer the older on-screen keyboard for some reason, you have two problems with your existing code.
Firstly, ms-appx: scheme is used to refer to files at the application installation path. The path you require is an absolute path, so you can't use it there.
Secondly, as this is an arbitrary path on the hard drive, you don't have access to it directly (as UWP apps run in a sandbox and can't access the filesystem directly for security reasons). To access the file, you will need to declare the broadFileSystemAccess capability, which will then allow you to initialize the StorageFile instance. You can check for example this SO question to learn how to do just that.
Note: I don't have my VS PC around so I can't say for sure if this will allow you to launch the executable or not, as that seems like an additional permission which may not be granted. In case this fails, I strongly recommend the first solution.
Make sure you edited the manifest file and add the extension for full trust process in the application.

Selectors only work when webpage is opened in Internet Explorer

I created a login sequence and my selectors for the input email, password, click login and element exists are valid. But only when I have the Internet Explorer page open on the website I'm working with.
I did that sequence again, and I ran it, initially it worked but when I ran the hole project it broke again, I tried "repair" and "indicate", I tried to eliminate the title but nothing is working.
As far as I can see, you are using selector attribute:
"title=ACME System 1 - Dashboard"
Try using a wildcard: title='ACME System 1*', so it can work when you leave the dashboard.
This worked for me when I took those UiPath Academy courses.
In order to automate tasks within a browser with UiPath, the browser must be open. There is an activity called Open Browser that's included in the default activities for every project. You need to add this activity to the beginning of your sequence and pass in the appropriate parameters, (ie. URL, browser type) you can then pass the outputted browser variable to an attach browser sequence and execute your browser automation acivities within that.
Browser activity sceenshot
In addition, the selector that you have shared does not look like a stable selector. There may be other 'H1' elements on the screen that will cause your automation to fail. I would use the UI explorer to help you build a better, more stable selector.
Did you initially use IE to indicate screen elements and then changed the BrowserType property to use a different browser? Please share the sequence to suggest you a fix for your issue.
I would also suggest you to modify the selector to 'title='ACME System *'.
In order for selector to work the application needs to be open and the desired element needs to be available. So when you close the browser the selector disappears.
You may consider swithching to 'Modern Design Experience' and use 'Use Application/Browser' scope to make this more intuitive, and it will also automatically open the browser for you if it is closed.

How to read profile preferences from Firefox add-on?

I'm doing this (Firefox 66.0.5, MacOS):
var prefs = Components.classes['#mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
var x = pref.getCharPref('extensions.foo.x');
I'm getting this:
JavaScript error: moz-extension://9390a488-d749-d140-91b6-fb1b2a86053f/foo.js,
line 1: TypeError: Components.classes is undefined
What is the right way to read the preferences of the profile?
I tried this:
var prefs = Components.classesByID['#mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
And got this:
JavaScript error: moz-extension://ebac8f96-717d-0c4b-b2d3-a7d6f3515843/auth.js,
line 1: TypeError: Components.classesByID is undefined
WebExtensions are very limited in their ability to make changes to user preferences. There are a few, currently 14, that you can affect through the browserSettings API. There are others which are effectively changed through other WebExtension APIs (e.g. proxy), but nothing directly. Unfortunately, there's no direct way to read or set user preferences from a WebExtension. The capability to adjust user preferences directly was only available to the older styles of add-ons (all removed as of Firefox 57).
As to your use of Components and the specific errors which you are getting, please see my answer to Unable to use Components in WebExtensions: get “ReferenceError: Cu is not defined” for more detail. The use of Components is just not possible in a WebExtension.
The only way that I can think of that it might be possible to adjust preferences in a release version of Firefox is to use Native messaging to communicate to a native application which you also install. After Firefox exits/stops/is shutdown, the native application could read and change the configuration files in the profile directory for the Firefox profile being run. It could then restart Firefox.
In the Nightly and Developer Edition versions of Firefox, it should still be possible to use a WebExtensions Experiment, which would permit you to make the preference changes you desire using the Components interface. However, that's not a viable solution if this is an extension you want to distribute publicly.

Using OSX Security-Scoped Bookmarks in a Firemonkey app

I have been developing an OSX app with Delphi XE3 and running into various problems. The latest one is with the sanboxed version built for the Apple Appstore.
The user has to select an arbitrary folder and the app needs to get access to it. Since there is a problem with the OpenDialog, I had to turn to drag-drop functionality instead.
The user drags a folder to the app, the sandbox gives the app temporary access to it and all works properly.
To preserve the access to this folder when the app is restarted I have to use the so-called "security-scoped bookmarks"
I am having two issues with them:
1) How to add the "com.apple.security.files.bookmarks.app-scope" entitlement to an XE3 firemonkey app? It is not available in the Project Options->Entitlements. If I add it manually in the ".entitlements" file it gets overwritten when the app is built.
So is there a way to add a custom entitlement that is not in the list in the project options?
2) To create the bookmark I should use the NSURL.bookmarkDataWithOptions method. I think it should be used like this, but I am not sure of the exact syntax:
var
URL: NSURL;
Err: NSError;
Data: NSData;
...
URL := TNSURL.Create;
Data := URL.bookmarkDataWithOptions(NSURLBookmarkCreationWithSecurityScope, nil, #Err);
...
Maybe there should be a call to Wrap(...) instead of Create.
I have not yet experimented with it, because it is pointless without the answer to issue 1).
It seems no one has written anything about these problems for Delphi, but I hope someone here has experience with that.
Thanks in advance.
Edit:
For problem 1) I tried to add edit manually the ".entitlements" file in the OSX32 folder and set it to read-only to prevent it from being overwritten. It was too easy to be true of course, because the linker complained that the file can not be modified...
OK, I finally found the way to manually add entitlements that are not available in the Project Options > Entitlements.
Instead of selecting the "App Store" build in the Project Manager you have to select a Normal release build and deploy the application as usual.
The application gets deployed in the PAServer scratch-dir as APP package. Inside this package there is an "Entitlements.plist" file, which is in XML format and can be edited with a text editor. It is quite obvious how to add new entitlements once you open the file.
After it is edited, the app has to be code-signed manually and a package has to be prepared. It is slightly more complicated than using the Delphi IDE, but there are instructions about it on the Embarcadero and Apple websites and it actually went without problems.
Still haven't tried the bookmarkDataWithOptions functions.
An alternative could be to deactivate the checkbox for the entitlements-file in the deployment page.
But attention: Evry time you change between Build/Release or App Store/Normal, delphi activates the checkbox. That means you have to deactivate it again in the deplayment-page, to avoid the transfer of this file to the mac PC.
By the way: Do you have tryed meanwhile the StartAccessingSecurityScopedResource function?
In the MacApi.Foundation unit the function is not declared in the NSURL interface.
Do you have found a way to use this function?

How to monitor global use of OSX application services?

Open a TextEdit document with a few words in it. Notice that when you right click on a word, you can click "Look up (Word)" to get its definition or "Speech Start Speaking" to hear it read out aloud.
How can I build a local application to monitor globally whenever a user has requested a dictionary definition or the speech synthesizer?
Couple of ways I can think of are
injection and Hooking. If its cocoa application you can also try swizzling. I think with this approach its very easy to manage what you are trying to do. But it can be lot of work.
If you follow apple techniques so they must be sending notification that can be catch between applications. Try to find them and you are done.

Resources