I have created an app in nw.js & it is running fine.
I have a requirement that I create a button in nwjs app (html page), and its click should open another .exe file in the user system(probably in the same directory along with nwjs.exe).
Can I do that and how?
Thanks
var exec = require('child_process').execFile;
exec('C:/asd/test.exe', function(err, data) {
console.log(err)
console.log(data.toString());
});
Related
I've built an electron app which is only executable if I directly execute the file (double click or via Terminal) locates at MyApp.app/Contents/MacOs/MyApp.
When I click the app MyApp.app directly via Finder electron window appears but only with an empty window. The backend isn't starting and so no frotend appears. The dificult thing here actually is that there isn't any logging/error message(s) that help me to understand whats not working here.
The App is built using this command:
electron-packager --asar . MyApp --ignore='^/build' --platform=darwin --arch=x64 --overwrite
Inside the electron app (simplified) I start an express server beside the main electron process:
// The express application
require(path.join(__dirname + "/bundle/dist/server"));
// Standard electron scaffolding
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, "scripts/preload.js"),
},
});
setTimeout(() => {
win.loadURL("http://localhost:1234");
}, 1000);
};
Can someone maybe give me an advice why it's only starting when going the way via Package content and not directly by clicking the app icon?
I'm really confused about how to properly copy files and grant permission to execute e.g. an AppleScript file from a sandboxed application. I've read several articles and threads but the more I read, the more it confuses me.
The Task
My app needs to run a very simple AppleScript from an .scpt file. To do so (if I got this right), I need to copy this file into Users/thisUser/Library/Application \Scripts/.com.developerName.appName/. Before I can interact with this folder the user needs to grant access to that folder. This can be done by showing the user an NSOpenPanel where he can select the path. After confirmation the app has access to that path and I can copy the file and later run the script (App Sandbox User Selected File must be read/write). So far so good.
The Problem(s)
I find presenting a Finder window with an empty folder to select very user unfriendly, so I was wondering if there is anything else I can do. The closest what I have found regarding this problem is drag & drop the folder "into the app" - details can be found here.
I guess I'm not the only person ever who created a (sandboxed) app which needs to run specific scripts and I can't believe that the above approach is the only possible solution!? Therefore,
can I not just have a single window with an OK button and some information above that the app needs permission to write into that folder without showing an entire Finder window?
When I was looking around for solutions I also came across several settings for the app itself. Unfortunately, the docs are very limited here and I could not really find out what the specific settings actually do and how I could test them (admittedly this is because this is my first ever app for OSX and I have basically no clue what I'm doing). One of which is the Copy Files option in the Build Phase settings of the app:
This did sound promising to me since I thought that if I install the app it will automatically copy the file to the Scripts destination (probably with some sort of user prompt) and I can use it. But it does nothing. There is no copy happening at any time, even if I deselect the Copy only when installing setting. I have also tried the different destination folders which are available in the dropdown
and unfortunately also here I
could not find out what the destinations are
nor the file has been copied to any of the destination folders on build.
I know that people here don't really like to answer questions like this in much detail since it is probably more a lack of knowledge on my side but I would really appreciate it if someone could at least help me getting into the right direction and direct me to some resources which tackle my problem!
Thanks!
Well, it seems like I have found a solution which (at least for me) seems to be more or less user friendly and within Apple's sandbox guidelines.
Again, I'm very new to app development using Xcode and SwiftUI so I'm not sure if this solution is 100% "the right way of doing it". But since it took me ages to find this out, maybe someone else can use it and speed up development!
Solution
Like I have mentioned in my question above, I was trying to get rid of the (in my opinion) pretty annoying NSOpenPanel Finder prompt, where the user is supposed to select the folder. I further asked about the Copy Files setting in the app's Build Phase tab - it turned out that this was the solution! Unfortunately, I still don't have any clue about the list of destination which are presented in the dropdown but choosing Absolute Path and inserting
Users/$USER/Library/Application Scripts/$PRODUCT_BUNDLE_IDENTIFIER
did the job! The file gets copied on every build into the app's Application Scripts directory, from which I can run scripts outside the sandbox. 🙌
The next step was to create a class which executes the script using NSUserScriptTask
import Foundation
class ExecuteAppleScript {
var status = ""
private let scriptfileUrl : URL?
init() {
do {
let destinationURL = try FileManager().url(
for: FileManager.SearchPathDirectory.applicationScriptsDirectory,
in: FileManager.SearchPathDomainMask.userDomainMask,
appropriateFor:nil,
create: true)
self.scriptfileUrl = destinationURL.appendingPathComponent("CreateMailSignature.scpt")
self.status = "Linking of scriptfile successful!"
} catch {
self.status = error.localizedDescription
self.scriptfileUrl = nil
}
}
func execute() -> String {
do {
let _: Void = try NSUserScriptTask(url: self.scriptfileUrl!).execute()
self.status = "Execution of AppleScript successful!"
} catch {
self.status = error.localizedDescription
}
return self.status
}
}
Then I have created a Button View which handles the request
import SwiftUI
struct GenerateSignatureButtonView: View {
#State var status = ""
var body: some View {
VStack(alignment: .center) {
Button(action: {
self.status = ExecuteAppleScript().execute()
})
{
Text("Generate Signature")
}
Text("\(self.status)")
}
}
}
struct GenerateSignatureButtonView_Previews: PreviewProvider {
static var previews: some View {
GenerateSignatureButtonView()
}
}
When clicking the button a window pops up that the app wants access to control (in my case) the Mail app.
This user prompt repeats every time the user closes the app, reopens it and clicks the button again. I guess this can be somehow managed with Security-Scoped-Bookmarks but I'm not yet sure how. Furthermore, the error handling is not really working in this example since the popup appears after the successful message appears in the status field. This is probably another big thing to figure out... Asynchronous?
Well, hope this helps!
in my windows cordova application I try to download a file, with the following function (I just copied the code from here):
var uri = Windows.Foundation.Uri(contentUrl);
var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
var download = downloader.createDownload(uri, file);
download.startAsync().then(function () {
console.log("FOOO DONE !");
}, function(error) {
console.log("Error while downloading file ", error);
});
The contentURL and the file are valid and the files are generated as well. But the download is not starting at all, the file, which was created has just the size of 0kb.
And also no error and success is printed.
What could be wrong ? Thanks in advance.
I had the same problem using the exact same code; what fixed it for me is changing the name of the package name (in the package.appxmanifest file) and/or the build number. For some reason I have to do this procedure every day since the downloads don't seem to work when i boot the pc.
I came to the conclusion that it's either a hardware problem or a Visual Studio issue, the code works just fine (once it starts working).
i create a simple mvc3(razor) web application and want to use it "for my customers to download files from my site".
it works fine on local host but when i upload it on my host when user press download button the browse dialog box come up to download it can not realize file tipe and say unknown file and remove file extension for example :
"test.rar" will convert to "test" with no file extension.
i tested it on Firefox 12 and ie8 they show one behavior.
please help me
my code:
public ActionResult down(string id)
{
return File(#"c:\test.rar", "rar", "test.rar");
}
Try to change content type to application/x-rar-compressed or application/octet-stream.
In an Win/IE environment with the right settings you can fire up a .exe file.
The following code runs fine to fire up Microsoft Lync (the new name for Office Communicator).
...
start chat
</body>
</html>
<script type="text/javascript">
function fnShellExecute()
{
var objShell = new ActiveXObject("shell.Application");
objShell.ShellExecute("communicator.exe", "", "C:\Program Files (x86)\Microsoft Lync", "open", 10);
}
</script>
But I can't work out the parameters (or if it is possible) to create a shortcut that would open the Lync client with the chat box to another available user open. Basically I know who is available and I want to be able to create (in HTML) a simple link that would open a chat window to that person (outside of WPF or Silverlight or any of the built in controls).
Does anyone know how to adjust this line in the javascript to open a Lync chat window to a specified contact?
objShell.ShellExecute("communicator.exe", "", "C:\Program Files (x86)\Microsoft Lync", "open", 10);
Or if there is another way to open Lync in chat mode via some kind of shortcut?
Thank you in advance.
Depending on your requirements, the easiest will be to use the existing NameCtrl persona menu - this is the pop-up menu that gets displayed in SharePoint (and other web-based apps like Dynamics CRM) when hovering over a users presence icon. This menu allows you to call the user, start a new conversation etc. You'd need Office installed on the machine you are running on in order for it to work.
As an example, try this on any client machine running Office 2007/2010 and IE. Hover over the "Your Contact" text to see the persona menu:
<script>
var sipUri = "your.contact#your.domain.com";
var nameCtrl = new ActiveXObject('Name.NameCtrl.1');
if (nameCtrl.PresenceEnabled)
{
nameCtrl.OnStatusChange = onStatusChange;
nameCtrl.GetStatus(sipUri, "1");
}
function onStatusChange(name, status, id)
{
// This function is fired when the contacts presence status changes.
// In a real world solution, you would want to update an image to reflect the users presence
alert(name + ", " + status + ", " + id);
}
function ShowOOUI()
{
nameCtrl.ShowOOUI(sipUri, 0, 15, 15);
}
function HideOOUI()
{
nameCtrl.HideOOUI();
}
</script>
<span onmouseover="ShowOOUI()" onmouseout="HideOOUI()" style="border-style:solid">Your Contact</span>
If the NameCtrl answer doesn't meet your requirements, you could try the Lync SDK. It would be pretty straightforward to create a .NET DLL that uses the Automation API to open a conversation with a given user.
You would then need to expose this via COM to ensure it could be called from JavaScript. Again, pretty straightforward using .NET's COM Interop features.